Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.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++_List - Fatal编程技术网

C++链表推送错误

C++链表推送错误,c++,list,C++,List,获取错误 tryout.cpp:29: error: no matching function for call to 'std::list<char, std::allocator<char> >::push_back(std::string&)'/opt/csw/gcc4/lib/gcc/sparc-sunsolaris2.8/4.0.2/../../../../include/c++/4.0.2/bits/stl_list.h:773: note: can

获取错误

 tryout.cpp:29: error: no matching function for call to 'std::list<char, std::allocator<char> >::push_back(std::string&)'/opt/csw/gcc4/lib/gcc/sparc-sunsolaris2.8/4.0.2/../../../../include/c++/4.0.2/bits/stl_list.h:773: note: candidates are: void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = char, _Alloc = std::allocator<char>]
试图使用参数将.text文件推送到列表中,但无法推送 代码如下

 int main (int argc, char* argv[])
 {


    string vowels;
    list<string> myList;

    ifstream infile(argv[1]); 

    //open the file

    if (infile.is_open() && infile.good()) {

       while (infile.get(vowels))) {        
       myList.push_back(vowels));

    infile.close();
    return 0;
 }

首先清除混乱。此外,由于懒惰,您的测试用例缺少一些头和一些std::实际错误是:没有匹配的函数用于调用“std::basic\u ifstream::getstd::string&”
int main(int argc, char* argv[]){
    char vowels;
    list<char> myList;
    ifstream infile(argv[1]);

    if (infile.is_open() && infile.good()) {
        while (infile.get(vowels)) myList.push_back(vowels);
        infile.close();
    }
    return 0;        
}