![]() |
|
#1
|
|||
|
|||
convert char array into CString?is it possible to convert a char array into a cstring?
i am trying to input strings from a file (using fstream) and i can't seem to use a cstring directly so i need to convert a char array to cstring. please help! Last edited by LuciWiz : 20-Aug-2005 at 02:51.
Reason: moved thread to the correct forum
|
|
#2
|
||||
|
||||
|
What exactly do you mean? Do you want to be able to move from a string to a char *?
Example: CPP / C++ / C Code:
Or something of that nature? This is of course not actual code but I hope it exibits what you are after. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#3
|
|||
|
|||
|
:edit: for somem reason when i try to define a string rather than a CString i get "undefined identifer" or something like that
this is basically what i'm triyng to do (this does not work) CPP / C++ / C Code:
this is not a console app by the way if that makes a difference Last edited by nasaiya : 04-Jun-2005 at 14:48.
Reason: incomplete
|
|
#4
|
|||
|
|||
|
can you use a regular std::string instead of a CString? Not using VC++, I don't know how to use CString, but with an std::string:
CPP / C++ / C Code:
also, @cable_guy_67: std::string::c_str member function returns a const char pointer, so you can't write to it with strcpy. |
|
#5
|
|||
|
|||
|
well i know that getline would work with a std::string but i still can't figure out why the compiler doesn't seem to recognize the declaration of a string.
i am using vc++ and the program is a dialog based mfc app. i tried putting the #include <string> in the app class's header file and the implementation cpp file but it still doesn't seem to include it or use it. i'm trying to do the file input within the App class's constructor... could this be why it doesn't work? |
|
#6
|
|||
|
|||
|
make sure to have somewhere
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#7
|
||||
|
||||
|
Not to be picky or anything but ...
CPP / C++ / C Code:
Code:
Go figure, I use it all the time. fltk dosen't use <string> so I use this when placing text in a display widget which is a char*. I may have been wrong in my assumption that by CString the OP meant a char array not a type named CString. So from <string.h> Code:
Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#8
|
|||
|
|||
|
all right, fine. my mistake. i had the order of strcpy's parameters wrong
|
|
#9
|
|||
|
|||
|
would there happen to be a way to convert a std string to a CString or LPCTSTR? because the SetWindowText functions of some of my dialog box controls will only accept those or something in quotes but that won't work. i was able to define a std string after adding using std::string but i still can't pass the data from the string to the dialog box because of the CString/LPCTSTR requirement. any ideas?
|
|
#10
|
|||
|
|||
|
nevermind i got it-- thanks for the help
|
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ PhoneBook | marita | C++ Forum | 46 | 12-Jun-2005 12:10 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 21:26 |
| Compiling Errors | ToddSAFM | C++ Forum | 22 | 18-Dec-2004 11:42 |
| convert long to pointer to char | realpopeye | C++ Forum | 2 | 26-Sep-2003 10:22 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The