0
我想做一個基本的解析爲用戶輸入的特殊字符的REPL。 This後顯示如何拆分空白,但當我嘗試將字符串流存儲到字符串的向量時,我得到此編譯錯誤。C++ istringstream基於範圍的循環沒有開始成員
repl.cpp: In function ‘int main(int, char**)’:
repl.cpp:52:25: error: range-based ‘for’ expression of type ‘std::__cxx11::basic_istringstream<char>’ has an ‘end’ member but not a ‘begin’
for (string s : iss)
^~~
repl.cpp:52:25: error: ‘std::ios_base::end’ cannot be used as a function
make: *** [repl.o] Error 1
這裏是低於全碼:
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <fstream>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
using namespace std;
int main(int argc, char *argv[])
{
size_t pos;
int pipe = 0;
int pid = 0;
vector <size_t> positions;
vector <string> arguements;
do
{
cout << "repl$ ";
getline(cin, cmd);
pos = cmd.find("|", 0);
while (pos != string::npos)
{
positions.push_back(pos);
pos = cmd.find("|", pos+1);
pipe += 1;
pid += 1;
}
istringstream iss(cmd);
while (iss >> cmd)
arguements.push_back(cmd);
for (string s : iss)
cout << s << endl;
} while (cmd != "q");
return EXIT_SUCCESS;
}
您是不是要找'的(字符串s:arguements)'?流不能像那樣工作。 –