C++: char* to string, converting? rewriting program? need substr!
Hi there!
I'm writing an app in C++.. I need a function similar to SUBSTR in the string class. however, I'm doing it the char way (no good reason why, though) I want to print "messy" from an index value of 6 (or so). But I can't seem to do find a function to do this in the classic string.h How would I convert this to string class? or, is there a method of doing what I want in string.h? Thanks for any help. Relevant code is below. char buffer[1000]; char buffer1[1000]; char titlestr; char * messy; if (! messagefile2.is_open()) { cout << "Error opening file"; exit (1); } while (! messagefile2.eof()) { messagefile2.getline(buffer,1000); strcat (buffer, "\n"); strcat (buffer1, buffer); } cout << buffer1; // memcpy (titlestr,buffer,strlen(buffer)+1); messy = strstr (buffer1, "Title:"); messy = strtok (messy, "\n"); cout << messy << "\n"; |
messy = messy+7;
omg! thanks lrt2003 :) |
I would also suggest considering the good old C function "sprintf" which is getting out of fashion nowadays but which is extremely powerfull.
|
All times are GMT -5. The time now is 06:04 AM. |