ei .. i'm new to c++ .. i have a little experience in vb .. my question is how can i cut the string in c ++ like in vb ....
This is a discussion on How can i cut the string ..???:(( within the C++ Programming forums, part of the General Programming Boards category; ei .. i'm new to c++ .. i have a little experience in vb .. my question is how can ...
ei .. i'm new to c++ .. i have a little experience in vb .. my question is how can i cut the string in c ++ like in vb ....
Do you mean tokenize the string? Break it into parts where it's separated by a certain character?
Cut the string? You mean make substring from a given string? Use the substr member function.
[edit]Please clarify what you mean by "cut".[/edit]Code:string str = "Hello World"; cout << str.substr(6) << endl; // Outputs "World" cout << str.substr(6,2) << endl; // Outputs "Wo" cout << str.substr(0,5) << endl; // Outputs "Hello"
Last edited by hk_mp5kpdw; 06-09-2005 at 01:44 PM.
I used to be an adventurer like you... then I took an arrow to the knee.
yeah !! how can i do that ??
I mean break it into parts or cutting it 1 by 1 .. how can i do that ??
You can refer to individual characters in the array.
Code:char array[30]; array[0] = 'A'; // first character array[1] = 'B'; // second character, etc...
Do this, write out an example of what exactly you want to do.
hk_mp5kpdw already gave an example of how to pull substrings out.
can someone show me a complete running code sample of cutting a string .... i want to cut the string an add it (E.G I input this number 123 , then the output should came out with 6 ) ........ with no limitation in inputing ..
I doubt anyone's going to write a complete program for you, because this sounds a lot like a homework assignment. You could just run your string through a loop that performed a switch/case statement on each element. If it was a number, add that number to a running total. If it was a null character, exit out of the loop.