Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

Reply
Thread Tools

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

 
 
aarthi28@gmail.com
Guest
Posts: n/a
 
      06-17-2007
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

#include <iostream>
#include <fstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <math.h>
#include "string.h"

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 With Quote
 
 
 
 
Baltimore
Guest
Posts: n/a
 
      06-17-2007
On 17 juin, 11:52, (E-Mail Removed) wrote:
> 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
>
> #include <iostream>
> #include <fstream>
> #include <iterator>
> #include <algorithm>
> #include <vector>
> #include <math.h>
> #include "string.h"
>
> 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;
>
> }


Can you give your compiler version and the line of the error, please ?

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-17-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.


It doesn't look like you are doing anything wrong, the code in question
looks fine to me.

--
Ian Collins.
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      06-17-2007
Baltimore wrote:
> On 17 juin, 11:52, (E-Mail Removed) wrote:
>> for (unsigned int i=0; i<n_word_list.size(); i++)
>> {
>> out_n << n_word_list.at(i) << endl; //ERROR
>> }
>> return 0;
>>
>> }

>
> Can you give your compiler version and the line of the error, please ?
>

Did you have to quote the entire post to ask that?

--
Ian Collins.
 
Reply With Quote
 
aarthi28@gmail.com
Guest
Posts: n/a
 
      06-17-2007
I am using Visual Studio 2005, and I marked the two lines that are
giving me errors in my original post. I am re-posting the error
portion here.
Thank you

..
..
..
..
for (unsigned int i=0; i<a_word_list.size(); i++)
{
achar = a_word_list.at(i);
out_a << achar << endl; //ERROR
}

..
..
..

for (unsigned int i=0; i<n_word_list.size(); i++)
{
out_n << n_word_list.at(i) << endl; //ERROR
}
return 0;
..
..
..

 
Reply With Quote
 
aarthi28@gmail.com
Guest
Posts: n/a
 
      06-17-2007
Is there something else I can do to make this run? I don't know why I
am getting an error

 
Reply With Quote
 
Roland Pibinger
Guest
Posts: n/a
 
      06-17-2007
On Sun, 17 Jun 2007 09:52:06 -0000, (E-Mail Removed) wrote:
>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
>
>#include <iostream>
>#include <fstream>
>#include <iterator>
>#include <algorithm>
>#include <vector>
>#include <math.h>
>#include "string.h"


#include <string>


--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      06-17-2007
(E-Mail Removed) wrote:
:: 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
::
:: #include <iostream>
:: #include <fstream>
:: #include <iterator>
:: #include <algorithm>
:: #include <vector>
:: #include <math.h>
:: #include "string.h"
::
:: using namespace std;
::

The operators for std::string are found in the <string> header.


Bo Persson


 
Reply With Quote
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      06-17-2007
On 2007-06-17 11:52, (E-Mail Removed) wrote:
> 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
>
> #include <iostream>
> #include <fstream>
> #include <iterator>
> #include <algorithm>
> #include <vector>
> #include <math.h>
> #include "string.h"


That does not look right to me. What does "string.h" contain? If you
wanted to use the C string header you should have used <string.h> or
<cstring>. However I suspect that you wanted to use C++ strings, in
which case you should use <string> (notice that none of the standard C++
headers have a .h when including). If you use <string> instead of
"string.h" your code will compiler just fine.

--
Erik Wikström
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      06-17-2007
(E-Mail Removed) wrote:
> 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


You are forgetting

#include <string>

No .h and <> not ""

john
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
type 'slice' is not an acceptable base type Antoon Pardon Python 2 12-21-2005 09:36 AM
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another ERROR SyrUser03 ASP General 2 03-11-2005 04:25 PM
DataAdd Error: Arguments are wrong type or are out of acceptable r Jack ASP General 1 12-14-2004 11:55 PM
Unsupported error,& Right operand of "Divide" operator must be a power of 2.. Kim JM VHDL 1 04-02-2004 06:58 PM
"Arguments are of the wrong type, out of acceptable range" error J. Muenchbourg ASP General 1 07-25-2003 02:34 PM



Advertisments