Simple solution to sstream input and output stream

Simple solution to sstream input and output stream

Since the use of sstreeam input and output streams has not been well understood, the last time I used it was used for data type conversion. Today, I will learn more to consolidate and deepen my understanding.

C++ primer 's explanation of sstream is: sstream header file defines three types to support memory IO, these types can write data to string, read data, just like string is an IO stream.

istringstream reads data from string to memory;
ostringstream reads from memory and writes data to string;
stringstream can read data from string or write data to string;

Specific use ------ data type conversion
int /double /...->string

#include <iostream>
#include <sstream>     //输入输出流头文件
using namespace std;
int main()
{
    
    
	stringstream ss;   
	//stringstream完成内存string的IO;
	string s;
	int n = 1000;
	ss << n;   //将数据n读入内存
	s=ss.str();  // 将内存流中的数据以str的形式读取,存入string
 	cout<<s;   
	//cout << ss.str();
	return 0;
}

I only know these at present, and continue to add them later. . . . .

Guess you like

Origin blog.csdn.net/weixin_43420303/article/details/109383121