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 ....
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.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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.