+ 1
How to loop through a string in C++?
I'm doing a project and got stuck on this. Can someone help?
6 Answers
+ 9
Here are three different ways to loop through a string in C++
https://code.sololearn.com/cw39FUF5d5Um/?ref=app
+ 7
string s = "blah blah";
for (char c : s) {
doStuff(c);
}
+ 6
you need to use stringstream
look at this code to learn how to use stringstream
this code reading every word from a string
if you want to read every letter
replace the string word; with char letter;
https://code.sololearn.com/cxbsvjtABY48/?ref=app
+ 6
doStuff(c) is shorthand for "do whatever you need to do with c". It could be a function that maps each c its ascii number + 7, or whatever.
+ 2
Eric, in your first answer, what does the "doStuff(c)" mean?
+ 1
Got it, thanks!