C++之stringstream(字符串与数字相互转换)

1.stringstream数字与字符串相互转换
#include 
#include 
#include 
#include 
using namespace std;
int main()
{
  stringstream  stream;
  string buf = "1234";
  int i;

  //1.字符串转换为整形
  stream << buf;//插入字符串
  stream >> i; //字符串转换成int类型
  cout << "typeinfo(i) = " << typeid(i).name() << ", i = "<< i <> buf;//将int类型转为字符串,放入buf
  cout << "typeinfo(buf) = " << typeid(buf).name() << ", buf = "<< buf <
#include 
#include 
#include 
using namespace std;

int main(){
  stringstream  stream;
  int port = 1;

  stream << "/dev/video" << port; //: /dev/video0 
  string str(stream.str());
  cout <<"stream.str() = " << stream.str() <

你可能感兴趣的:(C++学习)