CString parsing
-
Hey all I need some "C++ 101" help, I am working on a function that reads in a string and converts it into a CTime, using atoi( ):confused:. The function declaration is bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) any suggestions on how I can convert a string such as "12:00:00" into 12:00:00
-
Hey all I need some "C++ 101" help, I am working on a function that reads in a string and converts it into a CTime, using atoi( ):confused:. The function declaration is bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) any suggestions on how I can convert a string such as "12:00:00" into 12:00:00
GRAMI04 wrote: any suggestions on how I can convert a string such as "12:00:00" into 12:00:00 Read this: Date and Time in C++[^] :) -Nick Parker
-
Hey all I need some "C++ 101" help, I am working on a function that reads in a string and converts it into a CTime, using atoi( ):confused:. The function declaration is bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) any suggestions on how I can convert a string such as "12:00:00" into 12:00:00
The quoted article will help I'm sure, but I have found the following 2 approaches to be useful, alone or in combination. 1) The MFC COleDateTime class provides some string parsing capabilities, and you can then check the GetStatus() return code. 2) Alternatively, you could try something like: bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) { int hh, mi, ss; char ch; // ch catches junk beyond end of string if (sscanf(TimeStr, "%d:%d:%d%c", &hh, &mi, &ss, &ch) != 3) return false // now check for valid days of month etc. // The MFC classes can be used to do this. return whatever!! }