Tuesday, July 28, 2009

How do i break string in c++?

i have a problem that i need to fix : /





how would a string break??? example please

How do i break string in c++?
If you are looking to split a string into two separate strings, then the following code will do the job (assuming s as your string)





string one, two;





first = s.substr( 0, s.size()/2 );


second = s.substr( s.size()/2 );





That breaks it in half. Look up the substr function in your library documentation for more examples.
Reply:I'm not sure what you mean by break.





There are C routines span and brk, with equivalents for CString.





Tell me what your are trying to do, perhaps I can help.
Reply:you mean go down to the next line?





you use \n





though I think in linux its \r





like "this is going down to the next line\n"


No comments:

Post a Comment