+ 1

How to loop through a string in C++?

I'm doing a project and got stuck on this. Can someone help?

12th Dec 2017, 4:36 AM
DeltaTick
DeltaTick - avatar
6 Respuestas
+ 9
Here are three different ways to loop through a string in C++ https://code.sololearn.com/cw39FUF5d5Um/?ref=app
12th Dec 2017, 6:49 AM
Eric Blinkidu
Eric Blinkidu - avatar
+ 7
string s = "blah blah"; for (char c : s) { doStuff(c); }
12th Dec 2017, 4:43 AM
Eric Blinkidu
Eric Blinkidu - avatar
+ 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
12th Dec 2017, 8:13 AM
chris
chris - avatar
+ 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.
12th Dec 2017, 3:49 PM
Eric Blinkidu
Eric Blinkidu - avatar
+ 2
Eric, in your first answer, what does the "doStuff(c)" mean?
12th Dec 2017, 2:31 PM
DeltaTick
DeltaTick - avatar
+ 1
Got it, thanks!
12th Dec 2017, 4:38 PM
DeltaTick
DeltaTick - avatar