错误C2679:binary'<<':找不到运算符,它接受类型为'std :: string'的右手操作数(或者没有可接受的转换) [英] error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
问题描述
我写了这段代码,最后,我试图将一个
字符串向量写入文本文件。但是,我的程序也不是b
编译,当我尝试写入
文件时它给我以下错误:
error C2679:binary''<<'':找不到运算符,它取右手
类型''std :: string''的操作数(或者没有可接受的转换)
我不知道我做错了什么。我在这里发布了我的整个节目
。
谢谢
#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<< 打开异常文件时出错 <<结束;
}
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<< 打开普通文件时出错 <<结束;
}
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]))< br $>
{
a_word_list.assign(1," aa");
n_word_list.assign(1," aa" );
}
}
}
ofstream out_a(" 10_a_new.txt");
if(!out_a)
{
cout<< 打开新的异常文件时出错 << 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<< 打开新的普通文件时出错 << endl;
}
for(unsigned int i = 0; i< n_word_list.size(); i ++)
{
out_n<< n_word_list.at(i)<< ENDL; //错误
}
返回0;
}
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.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;
}
推荐答案
17月7日,11:52,aarth ... @ gmail.com写道:
On 17 juin, 11:52, aarth...@gmail.com wrote:
我已经编写了这段代码,最后,我正在尝试将一个
字符串向量写入文本文件。但是,我的程序也不是b
编译,当我尝试写入
文件时它给我以下错误:
error C2679:binary''<<'':找不到运算符,它取右手
类型''std :: string''的操作数(或者没有可接受的转换)
我不知道我做错了什么。我在这里发布了我的整个节目
。
谢谢
#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<< 打开异常文件时出错 <<结束;
}
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<< 打开普通文件时出错 <<结束;
}
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]))< br $>
{
a_word_list.assign(1," aa");
n_word_list.assign(1," aa" );
}
}
}
ofstream out_a(" 10_a_new.txt");
if(!out_a)
{
cout<< 打开新的异常文件时出错 << endl;
}
for(unsigned int i = 0; i< a_word_list.size(); i ++)
{
achar = a_word_list.at(i);
out_a<< achar<< ENDL; //错误
}
ofstream out_n(" 10_n_new.txt");
if(!out_n)
{
cout<< 打开新的普通文件时出错 << endl;
}
for(unsigned int i = 0; i< n_word_list.size(); i ++)
{
out_n<< n_word_list.at(i)<< ENDL; //错误
}
返回0;
}
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.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 ?
aa ****** @ gmail.com 写道:
我编写了这段代码,最后,我试图将一个
字符串向量写入文本文件。但是,我的程序也不是b
编译,当我尝试写入
文件时它给我以下错误:
error C2679:binary''<<'':找不到运算符,它取右手
类型''std :: string''的操作数(或者没有可接受的转换)
我不知道我做错了什么。
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.
看起来你做错了什么,有问题的代码
对我来说很好看。
-
Ian Collins。
It doesn''t look like you are doing anything wrong, the code in question
looks fine to me.
--
Ian Collins.
巴尔的摩写道:
Baltimore wrote:
On 17 juin,11:52,aarth ... @ gmail.com写道:
On 17 juin, 11:52, aarth...@gmail.com wrote:
> for(unsigned int i = 0; i< n_word_list.size(); i ++)
{
out_n<< n_word_list.at(i)<< ENDL; //错误
}
返回0;
}
> 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 ?
您是否需要引用整个帖子来询问?
-
Ian Collins。
Did you have to quote the entire post to ask that?
--
Ian Collins.
这篇关于错误C2679:binary'<<':找不到运算符,它接受类型为'std :: string'的右手操作数(或者没有可接受的转换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!