Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ getline(),delim未按预期工作_C++_Console Application_Getline_Split - Fatal编程技术网

C++ getline(),delim未按预期工作

C++ getline(),delim未按预期工作,c++,console-application,getline,split,C++,Console Application,Getline,Split,我想把它拆分成一个字符串,用逗号作为分词。我放了一个字符串“Smith,Erdos,William”,它只输出“William”,但不输出Smith和Erdos。这里一定有什么不对劲,我就是看不出来,有人能帮忙吗 #include <iostream> #include <string> #include <vector> #include <sstream> int main() { int numScenarios(0); i

我想把它拆分成一个字符串,用逗号作为分词。我放了一个字符串“Smith,Erdos,William”,它只输出“William”,但不输出Smith和Erdos。这里一定有什么不对劲,我就是看不出来,有人能帮忙吗

#include <iostream>
#include <string>
#include <vector>
#include <sstream>

int main() {
    int numScenarios(0);
    int numPapers(0);
    int numWriters(0);
    std::vector<std::string> paperTitles (1);
    std::vector<std::string> paperAuthors (1);
    std::vector<std::string> splitAuthors (1);
    std::string token;
    std::string input;
    std::cin >> numScenarios;
    std::cin >> numPapers >> numWriters; 
    for (int i(0); i < numPapers; ++i) {
        std::getline(std::cin,input);
        std::istringstream iss(input);
        while(getline(iss,token,','));
        {
            std::cout << token << std::endl;
        }
        //paperTitles.push_back(input);
        //input = '\0';
    }
    for (int i(0); i < numWriters; ++i) {
        getline(std::cin,input);
        paperAuthors.push_back(input);
        input = '\0';
    }


return 0;
}
#包括
#包括
#包括
#包括
int main(){
国际货币基金组织(0);
整数单位(0);
int numWriters(0);
标准:向量纸标题(1);
性病:病媒论文作者(1);
std::向量拆分器(1);
字符串标记;
std::字符串输入;
标准::cin>>numScenarios;
标准::cin>>numPapers>>numWriters;
for(int i(0);istd::cout
while(getline(iss,token,,);//在相关链接中发现了这个问题(这是一个您没有解决的问题):您似乎也会将内容推到向量的后面,但在创建过程中从不使用您放在那里的内容。
-Wempty body
(包含在
-Wextra
中)是你的朋友。虽然在第二次阅读时,
-Wempty body
只在
if
else
do…while
语句中警告空体,而不是
while
语句或常规
while
语句,所以它实际上在这里没有帮助。