繁体   English   中英

C ++链表Push_back错误

[英]C++ Linked List Push_back ERROR

遇到错误

 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;
 }
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;        
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM