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 677 views
1 answer 272 views
2 answers 353 views
1 answer 173 views
1 answer 184 views
184 views asked Jun 6, 2018 by avibootz
1 answer 162 views
1 answer 116 views
...