//我定义的结构
struct word
{
string data;
int    row;
int    line;
}word,*word_ptr;typedef struct word elemtype;
//创建了一个链表
list<elemtype> l;list<elemtype>::iterator it;
 for(it=l.begin();it!=l.end();it++)
{   
      cout<<(*it).data<<"行号:"<<(*it).row<<"  列号:"<<(*it).line<<endl;
}但是提示出错
Compiling...
file.cpp
C:\Documents and Settings\Administrator\桌面\读写文件\file.cpp(53) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (o
r there is no acceptable conversion)
执行 cl.exe 时出错.file.obj - 1 error(s), 0 warning(s)

解决方案 »

  1.   


    #include <iostream>
    #include <string>
    #include <list>using namespace std;struct word
    {
    string data;
    int row;
    int line;
    }word,*word_ptr;typedef struct word elemtype;int _tmain(int argc, _TCHAR* argv[])
    {
    list<elemtype> l; elemtype info;
    info.data = "Hello";
    info.row = 1;
    info.line = 2; l.push_back(info);

    list<elemtype>::iterator it;
    for(it=l.begin();it!=l.end();it++)
    {   
    cout<<(*it).data<<"行号:"<<(*it).row<<" 列号:"<<(*it).line<<endl;
    } return 0;
    }
      

  2.   

    我加了#include<fstream.h>后出现
    Compiling...
    045.cpp
    D:\vc++\MSDev98\Bin\045.cpp(32) : error C2872: 'cout' : ambiguous symbol
    D:\vc++\MSDev98\Bin\045.cpp(32) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion
    )
    执行 cl.exe 时出错.045.obj - 1 error(s), 0 warning(s)
    这样的错误