How to read string stream (stringstream) char by char in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>

using std::cout;
using std::endl;

int main()
{
	char ch;
	std::stringstream sst;

	sst << 3.14 << " + " << 0.5 << " = " << 3.14 + 0.5 << endl;

	do {
		ch = sst.get();
		if (!sst.eof()) cout << ch;
	} while (!sst.eof());
	
	cout << endl;

	return 0;
}

/*
run:

3.14 + 0.5 = 3.64

*/

 



answered Jun 18, 2018 by avibootz

Related questions

3 answers 653 views
1 answer 261 views
2 answers 342 views
1 answer 168 views
1 answer 174 views
174 views asked Jun 6, 2018 by avibootz
1 answer 151 views
1 answer 107 views
...