istringstream

来源:互联网 发布:首席数据官 能力描述 编辑:程序博客网 时间:2024/04/29 03:27
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
 
 string str,line;
 while(getline(std::cin,line))
 {
  long l=0;
  istringstream s(line);//istringstream对象可以绑定一行字符串,然后以空格为分隔符把该行分隔开来
  while(s>>str)
  {
   cout<<str.c_str();
  }
  s>>l; //这样就把字符串转成long型整数
  cout<<l<<endl;
 }
 return 0;
}
这里如果包含头文件写成:#include <iostream.h>会造成 和 using namespace std conflicts.
原创粉丝点击