Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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++ c++;字符串连接解决方案_C++_String - Fatal编程技术网

C++ c++;字符串连接解决方案

C++ c++;字符串连接解决方案,c++,string,C++,String,为什么这个代码不起作用?错误消息:main.cpp:147:5:错误:应为“;”在“fin”之前 string file; ifstream fin; fin.clear(); cout << "\n\t--------------------------------Enter Person's name then surname to display------"; cin>>file; file +=".txt"

为什么这个代码不起作用?错误消息:main.cpp:147:5:错误:应为“;”在“fin”之前

   string file;
    ifstream fin;
    fin.clear();

    cout << "\n\t--------------------------------Enter Person's name then surname to display------";
    cin>>file;

    file +=".txt"
    fin.open(file.c_str());

    char word[50];
    fin>>word;
    while(fin.good()){


        cout << word << " ";
        fin >> word;
    }


    system("pause");
    return 0;

}
字符串文件;
流鳍;
fin.clear();
cout>文件;
文件+=“.txt”
打开(file.c_str());
字符字[50];
fin>>单词;
while(fin.good()){
单词;
}
系统(“暂停”);
返回0;
}

您需要在此行末尾加一个分号:

file +=".txt"

这应该可以修复错误。

好吧,您缺少一个
文件+=“.txt”
之后

字符串文件;
流鳍;
fin.clear();
cout>文件;
文件+=“.txt”;
打开(file.c_str());
字符字[50];
fin>>单词;
while(fin.good()){
单词;
}
系统(“暂停”);
返回0;

}

您在下面的行中缺少分号

file +=".txt"   <-------- put a semi colon HERE
    fin.open(file.c_str());

file+=“.txt”哪一个是第147行?似乎有很多代码您没有显示错误说明了一切:您忘记了一个
在第146行(因为错误在第147行)。错误消息实际上告诉您错误是什么。它的fin.open(file.c_str());我会开始看第147行,但是当您尝试使用
(*l).SetName(name)
行时,会出现一个异常,因为您从未指向任何东西。谢谢。我不知道为什么Netbeans显示错误的行作为错误源。@BaturayE.H.AHMAD Netbeans不是问题所在。缺少
始终显示在下一行,而不是它实际缺少的行上。了解C++语法/解析器的工作原理,这将是有意义的。
file +=".txt"   <-------- put a semi colon HERE
    fin.open(file.c_str());