error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - aarthi2

17-Jun-07 06:12:45
Hi,
I have written this code, and at the end, I am trying to write a
vector of strings into a text file. However, my program is nor
compiling, and it gives me the following error when I try to write to
the file:

error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'std::string' (or there is no acceptable conversion)

I don't know what I am doing wrong. I have posted my entire program
here.
Thank you


using namespace std;

char n_str[2000];
char a_str[2000];

char n_char[2000];
char a_char[2000];
string achar, nchar;

int main(int argc, char* argv[])
{
vector<string> n_word_list;
vector<string> a_word_list;

ifstream in_a("10_a.txt");
if (!in_a)
{
cout << "Error opening abnormal file" << endl;
}
while (!in_a.eof())
{
in_a.getline(a_str,2000);
a_word_list.push_back(a_str);
}
cout << a_word_list.size()<< endl;

ifstream in_n("10_n.txt");
if (!in_n)
{
cout << "Error opening normal file" << endl;
}
while (!in_n.eof())
{
in_n.getline(a_str,2000);
n_word_list.push_back(a_str);
}
cout << n_word_list.size()<< endl;

for (unsigned int i=0; i<a_word_list.size(); i++)
{
for (unsigned int j=0; j<n_word_list.size();j++)
{
if (a_word_list[i].compare( n_word_list[j]))
{
a_word_list.assign(1,"aa");

n_word_list.assign(1,"aa");

}
}
}

ofstream out_a("10_a_new.txt");
if (!out_a)
{
cout << "Error opening new abnormal file" << endl;
}
for (unsigned int i=0; i<a_word_list.size(); i++)
{
achar = a_word_list.at(i);
out_a << achar << endl;  //ERROR
}

ofstream out_n("10_n_new.txt");
if (!out_n)
{
cout << "Error opening new normal file" << endl;
}
for (unsigned int i=0; i<n_word_list.size(); i++)
{
out_n << n_word_list.at(i) << endl;   //ERROR
}
return 0;

}
reply
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - aarthi2 17-Jun-07
        Re: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - David Lowndes 17-Jun-07
        Re: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Alex Blekhman 17-Jun-07
                Re: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Tim Roberts 19-Jun-07
                        Re: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Alex Blekhman 19-Jun-07
                                Re: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - David Wilkinson 19-Jun-07
                                        Re: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) - Alex Blekhman 19-Jun-07

Pass by value or reference
  

Search

search




Purchase