how does stringstream work

I do not understand the concept of stringstream

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <sstream> 
using namespace std;



int main(){
	string stringer = "234";
	stringstream ss(stringer); 
	int i;
	ss >> i;
	cout << i + 1 << endl; 

	int inter = 1231232354;
	stringstream num_str;
	num_str << inter;
	cout << num_str.str().substr(1,5) <<endl; 
	
}


How does this convert an int to a string. What does stringstream do to allow this?
1
2
	num_str << inter;
	num_str.str()

Last edited on
It's operator<< that performs the conversion, the same way it does it when you use std::cout or a file stream or any other output stream.

operator<< calls num_put::put(), you can read here on what that does: http://en.cppreference.com/w/cpp/locale/num_put/put
Topic archived. No new replies allowed.