【发布时间】:2016-11-29 18:44:18
【问题描述】:
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
vector<string> split_string(string s)
{
string buf;
stringstream ss(s);
vector<string> tokens;
while (ss >> buf)
tokens.push_back(buf);
return tokens;
}
int main()
{
cout << split_string("Alpha Beta Gamma");
}
当我尝试使用空格将字符串拆分为向量时,我无法打印出我的解决方案。
我不允许我使用 std::cout 但在我的函数中给出了返回值
为什么我不能那样使用它?我该如何解决这个问题?
【问题讨论】:
-
std::vector 没有重载运算符
-
这是和this one一样的赋值吗?