halluc1nati0n Posted February 7, 2010 Share Posted February 7, 2010 So, what's the easiest way to read one character at a time from a string/ stringstream in C++ and display it on the screen. I know it's easy, but somehow it's eluding me. istream.get()? Link to comment https://www.neowin.net/forum/topic/873294-reading-one-character-at-a-time-from-a-stringstringstream/ Share on other sites More sharing options...
0 ViZioN Posted February 7, 2010 Share Posted February 7, 2010 Yeah get() should do what you want. There's some more info here. halluc1nati0n 1 Share Link to comment https://www.neowin.net/forum/topic/873294-reading-one-character-at-a-time-from-a-stringstringstream/#findComment-592210816 Share on other sites More sharing options...
0 Ryuurei Posted February 8, 2010 Share Posted February 8, 2010 If you want to do something a little more personally coded (since I don't really know a lot of C++.NET specifically) you could do something like.... //... int n = sizeof(mychartext); for (int pos = 0; pos < n; pos++) { if (mychartext[pos] != ' ') //If the place where the position counter is not "space" { cout << mychartext[pos]; } else if (mychartext[pos] == '\0') //If the place where the position counter is on holds a null value... { break; //break the loop, as we have reached the end of the string. } else { continue; //Do nothing, and allow the for loop to bring position to the next character. } } feel free to correct me if this is flawed. Hopefully the general idea can give you another idea as to how you could do this. :) halluc1nati0n 1 Share Link to comment https://www.neowin.net/forum/topic/873294-reading-one-character-at-a-time-from-a-stringstringstream/#findComment-592216658 Share on other sites More sharing options...
0 ViZioN Posted February 9, 2010 Share Posted February 9, 2010 You don't need the continue in your loop Ryuurei. It'll cycle back up to the top anyway. Link to comment https://www.neowin.net/forum/topic/873294-reading-one-character-at-a-time-from-a-stringstringstream/#findComment-592216810 Share on other sites More sharing options...
0 halluc1nati0n Posted February 9, 2010 Author Share Posted February 9, 2010 Thanks ViZioN and Ryuurei. Forgot to mention, I've solved this using get() already and a stringstream :D Reps Time.. Link to comment https://www.neowin.net/forum/topic/873294-reading-one-character-at-a-time-from-a-stringstringstream/#findComment-592217282 Share on other sites More sharing options...
Question
halluc1nati0n
So, what's the easiest way to read one character at a time from a string/ stringstream in C++ and display it on the screen.
I know it's easy, but somehow it's eluding me. istream.get()?
Link to comment
https://www.neowin.net/forum/topic/873294-reading-one-character-at-a-time-from-a-stringstringstream/Share on other sites
4 answers to this question
Recommended Posts