string problem in VC++ Express

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
johncmk2003
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon Mar 27, 2006 9:22 pm

string problem in VC++ Express

Post by johncmk2003 »

I can't compile the following string


_("This is first line\n"
"This is second line")

under VC++ Express.

How to change it?
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Re: string problem in VC++ Express

Post by phlox81 »

try:

_("This is first line\n" \
"This is second line")
or
_("This is first line\n \
This is second line")
johncmk2003
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon Mar 27, 2006 9:22 pm

It is unicode problem

Post by johncmk2003 »

I forget to say it passed under non-unicode and fail under unicode.

I think "\"

is not the solution.
Thelvyn
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sun Feb 26, 2006 8:03 pm
Location: Linwood Pa USA
Contact:

Post by Thelvyn »

That code should work fine, ive been using strings like that since turbo C++ 1.x and its always worked with every compiler to date. I do not however have that compiler to test it on.

Maybe you could give us some more context and then we can ascertain what the real problem is.
sarat
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Feb 08, 2006 1:59 pm
Location: Bangalore
Contact:

Post by sarat »

Hi
the code posted abow is working .. i tested using Visual Studio .net Framework 2003
I tested like this

Code: Select all

wxString  test_string = _("This is first line\n"
		                       "This is second line");
and its getting compiled properly .. i guess its problem with something else can u tell what exactly u r doing there and can u post some of the code

the code abow shud not create any compilation error i guess
micros
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Sat Mar 18, 2006 10:41 am
Location: Ustek, Bohemia

Post by micros »

Code: Select all

str = wxT("first line\n"
  "second line");
Works as long as you don't have UNICODE defined. When you have UC, wxT prepends its argument with L, thus you get...

Code: Select all

str = L"first line\n"
  "second line";
...which is a concatenation of UC string with non-UC, thus illegal expression. So, if you need to concat string literals, you have to enclose each of them in wxT() separately (all of you, even those who report the above as working :)):

Code: Select all

str = wxT("first line\n")
  wxT("second line");
But perhaps you'd also like to try this way:

Code: Select all

str = wxT("\
first line\n\
second line");
johncmk2003
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon Mar 27, 2006 9:22 pm

Post by johncmk2003 »

micros,

Thank you for your correct reply.

So I summarize the right solution is

1. wxString str = wxT("first line\n")
wxT("second line");

2. wxString str = wxT("first line\n\
second line\n");

I think solution 1 is more elegant.

BTW, could you explain what is the difference between

"wxT()" and "_T()"?
micros
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Sat Mar 18, 2006 10:41 am
Location: Ustek, Bohemia

Post by micros »

I also use the 1st form, mainly because the second can't be indented properly. I only wanted the post to be complete.

No difference between wxT() and _T(). It's only that MSVC users are used to _T() from < tchar.h>. I also was. But since I switched to wxWidgets, I prefer wxT(). Even though it's longer, I like it more. Another silly argument is that identifiers beginning with two underscores or an underscore and a capital letter (i.e. matching /^_[_A-Z]/) are reserved in the C++ standard. Of course it's very unlikely _T will be used for anything else in any future library/compiler, because it's current purpose and use are so widespread.
Detrius
Knows some wx things
Knows some wx things
Posts: 42
Joined: Tue Mar 07, 2006 9:00 pm
Location: San Pedro, CA

Post by Detrius »

wxT() and _T() are identical, but _() does have a different purpose. _() is used to mark strings for translation (if you intend to ship your product in multiple languages). Therefore, strings like filenames or debug messages should use a wxT() variant, while user messages should use _().
Post Reply