-
Dec 29th, 2000, 01:37 PM
#1
Thread Starter
Lively Member
Anybody know of a way to convert a CString into a wstring?
If you drop a blond and a UNIX box out a window, which one lands first?
-
Dec 29th, 2000, 02:02 PM
#2
Monday Morning Lunatic
If UNICODE is defined, then you can use:
Code:
wstring str = LPCTSTR(myCString);
If not, then you'd have to use an ordinary string.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 29th, 2000, 02:26 PM
#3
Thread Starter
Lively Member
WHen I try that it returns:
error C2440: 'initializing' : cannot convert from 'const char *' to 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >'
No constructor could take the source type, or constructor overload resolution was ambiguous
I have defined Unicode like this:
#ifndef UNICODE
#define UNICODE
#endif
If you drop a blond and a UNIX box out a window, which one lands first?
-
Dec 29th, 2000, 02:28 PM
#4
Monday Morning Lunatic
It's giving a char error because CString doesn't think it's using Unicode. If you assigned it to a string, then it would be fine.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 29th, 2000, 02:39 PM
#5
Thread Starter
Lively Member
im not sure I follow. What am I assigning a string?
Do you mean:
string str;
CString Cstr;
wstring wstr;
wstr=Cstr=str;
??
If you drop a blond and a UNIX box out a window, which one lands first?
-
Dec 29th, 2000, 02:42 PM
#6
Monday Morning Lunatic
Code:
#ifdef _UNICODE
#define String wstring
#else
#define String string
#endif
String mystring;
CString myCString = "Hello";
mystring = LPCTSTR(myCString);
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 29th, 2000, 03:01 PM
#7
Thread Starter
Lively Member
It fails to recognize String as a datatype. Heres what I think you're getting at:
#include <windows.h>
#include <vector.h>
#include <lm.h>
#include <stdio.h>
#ifdef _UNICODE
#define String wstring
#else
#define String string
#endif
main()
{
String mystring;
CString myCString = "Hello";
mystring = LPCTSTR(myCString);
return 0;
}
And heres the build status:
--------------------Configuration: temp - Win32 Debug--------------------
Compiling...
temp.cpp
C:\temp.cpp(15) : error C2065: 'string' : undeclared identifier
C:\temp.cpp(15) : error C2146: syntax error : missing ';' before identifier 'mystring'
C:\temp.cpp(15) : error C2065: 'mystring' : undeclared identifier
C:\temp.cpp(16) : error C2065: 'CString' : undeclared identifier
C:\temp.cpp(16) : error C2146: syntax error : missing ';' before identifier 'myCString'
C:\temp.cpp(16) : error C2065: 'myCString' : undeclared identifier
C:\temp.cpp(16) : error C2440: '=' : cannot convert from 'char [6]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\temp.cpp(18) : error C2440: '=' : cannot convert from 'const char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
temp.exe - 8 error(s), 0 warning(s)
If you drop a blond and a UNIX box out a window, which one lands first?
-
Dec 29th, 2000, 06:38 PM
#8
Monday Morning Lunatic
AAAAARRRRGGGGHHHH!!!
Hehehe...you need to tell it you're using the string class...
Code:
#include <string>
using std::string;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|