c++记录

来源:互联网 发布:android答题系统源码 编辑:程序博客网 时间:2024/06/14 21:23

            • 使用istringstream区分待空格的字符串

使用istringstream区分待空格的字符串
    #include <sstream>    #include <string>    #include <vector>    #include <iostream>    vector<string> xlist;    string text = "abc def g h";    // 创建istringstream对象ss,把text传给ss    istringstream ss(text);    string word;    while (ss >> word) {        xlist.push_back(word);    }    // 循环输出xlist    for (vector<int>::size_type ix = 0; ix != xlist.size(); ++ix) {        cout << xlist[ix] << endl;    }
  • istringstream类用于执行C++风格的串流的输入操作。
  • ostringstream类用于执行C风格的串流的输出操作。
  • strstream类同时可以支持C风格的串流的输入输出操作。
原创粉丝点击