convert char to string
-
hi i noe this may sound simple but im having problem in converting char to string.
string get_currenttime(){
time_t rawtime;
string s1,
stringstream ss;
struct tm * timeinfo;
char buffer [80];time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%c",timeinfo); // result: Mon Nov 30 22:08:52 2009ss << buffer;
ss >> s1; //result: Mon
}From the above code which i found online, i need to convert the data in buffer to string. i tried using stringstream but results are not complete. See above for example
-
hi i noe this may sound simple but im having problem in converting char to string.
string get_currenttime(){
time_t rawtime;
string s1,
stringstream ss;
struct tm * timeinfo;
char buffer [80];time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%c",timeinfo); // result: Mon Nov 30 22:08:52 2009ss << buffer;
ss >> s1; //result: Mon
}From the above code which i found online, i need to convert the data in buffer to string. i tried using stringstream but results are not complete. See above for example
-
hi i noe this may sound simple but im having problem in converting char to string.
string get_currenttime(){
time_t rawtime;
string s1,
stringstream ss;
struct tm * timeinfo;
char buffer [80];time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%c",timeinfo); // result: Mon Nov 30 22:08:52 2009ss << buffer;
ss >> s1; //result: Mon
}From the above code which i found online, i need to convert the data in buffer to string. i tried using stringstream but results are not complete. See above for example
The difference in result that you see is because the
>> operator
will get characters only till a newline or space character. You could use thegetline
function to get the entire result. But the solution suggested byRichard MacCutchan
is simple and the best.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)