473,748 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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<stringn_ word_list;
vector<stringa_ 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.pus h_back(a_str);
}
cout << a_word_list.siz e()<< 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.pus h_back(a_str);
}
cout << n_word_list.siz e()<< endl;

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

n_word_list.ass ign(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.s ize(); 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.s ize(); i++)
{
out_n << n_word_list.at( i) << endl; //ERROR
}
return 0;
}

Jun 17 '07 #1
29 23214
On 17 juin, 11:52, aarth...@gmail. com 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<stringn_ word_list;
vector<stringa_ 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.pus h_back(a_str);
}
cout << a_word_list.siz e()<< 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.pus h_back(a_str);
}
cout << n_word_list.siz e()<< endl;

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

n_word_list.ass ign(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.s ize(); 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.s ize(); 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 ?

Jun 17 '07 #2
aa******@gmail. com 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.
Jun 17 '07 #3
Baltimore wrote:
On 17 juin, 11:52, aarth...@gmail. com wrote:
> for (unsigned int i=0; i<n_word_list.s ize(); 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.
Jun 17 '07 #4
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.s ize(); i++)
{
achar = a_word_list.at( i);
out_a << achar << endl; //ERROR
}

..
..
..

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

Jun 17 '07 #5
Is there something else I can do to make this run? I don't know why I
am getting an error

Jun 17 '07 #6
On Sun, 17 Jun 2007 09:52:06 -0000, aa******@gmail. com 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
Jun 17 '07 #7
aa******@gmail. com 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 <stringheader .
Bo Persson
Jun 17 '07 #8
On 2007-06-17 11:52, aa******@gmail. com 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.hor
<cstring>. However I suspect that you wanted to use C++ strings, in
which case you should use <string(notic e that none of the standard C++
headers have a .h when including). If you use <stringinstea d of
"string.h" your code will compiler just fine.

--
Erik Wikström
Jun 17 '07 #9
aa******@gmail. com 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
Jun 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9687
by: Rakesh | last post by:
In my Python code fragment, I want to write a code fragment such that the minimum element of a tuple is subtracted from all the elements of a given tuple. When I execute the following python script I get the following interpreter error.
6
12545
by: c++newbie | last post by:
Hi all, I try to compile the following classes: main.cpp: #include <algorithm> #include <iostream> #include <fstream> #include <iterator>
4
4779
by: bor_kev | last post by:
Hi! What's the syntax to overload the operator= under Microsoft Visual C++ .NET 2005 in a managed class. I tried : static Myclass^ op_Assign (Myclass^, Myclass^){} but it doesn't work. don't know why....
2
5366
by: michael.rygh | last post by:
This is just one of the sources for a project that deals with a library. I am having problems, here is the errors. all these.. i belive it has something to do with it needs a subscript? but i'm not exactly sure what to do.. (33): error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'char ' (or there is no acceptable conversion) 37): error C2679: binary '>>' : no operator found which takes a
1
31079
by: Florian Lindner | last post by:
Hello, I get the exception above when trying to use a float as radix and exponent, e.g.: Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: unsupported operand type(s) for ^: 'float' and 'float' How can I use floats for powers?
4
5468
by: lothas | last post by:
Hi, I'm working on a project to create a robotics simulation environment based on c++ and opengl. Right now I'm stuck trying to solve a compilation error that I'm getting while trying to push_back an object from one of my classes. Here's part of the code: class RobotStruct { public: RobotStruct(); virtual ~RobotStruct(); void AddJoint(float Theta, float Alpha, float a, float d, int Type); void PopJoint(int ID) {...
1
2781
by: Terry Archer | last post by:
Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) #include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { string lastName1, firstName1, lastName2, firstName2, lastName3, firstName3; double currentSalary1, currentSalary2, currentSalary3;
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9253
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.