使用ofstream编译错误 [英] compilation error using ofstream
问题描述
您好,有没有人对此错误有任何疑问?以及如何解决它?
这对我来说似乎微不足道,但对于编译器却没有。我在Ubuntu Linux系统上使用g ++
4.2:
// main()
....
std :: ofstream fout;
fout.open(" hello.out");
fout<< setfill('' - '')<< setw(20)<<" - "<< setfill('''')<< endl;
fout<< 你好; //这是第139行
....
main.cxx:89:从这里实例化
main.cxx :139:错误:ISO C ++说这些都是模棱两可的,即使是
虽然第一个最差的转换比第二个最差的转换
更好:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735:注意:候选人1:std :: basic_ostream< char,_Traits>&
std :: operator<<(std :: basic_ostream< char,_Traits>& ;,const char *)[with
_Traits = std :: char_traits< char>]
Domain.h:507:注意:候选人2:o& operator<<(o&,const Domain&)
[with o = std :: ofstream]
make:*** [main.o]错误1
谢谢大家!
a2
Hello, does anyone have a clue about this error? and how to solve it?
It seems to be trivial to me, but not for the compiler. I''m using g++
4.2 on an Ubuntu Linux system:
// main()
....
std::ofstream fout;
fout.open("hello.out");
fout<<setfill(''-'')<<setw(20)<<"-"<<setfill('' '')<<endl;
fout<<"hello "; // this is line 139
....
main.cxx:89: instantiated from here
main.cxx:139: error: ISO C++ says that these are ambiguous, even
though the worst conversion for the first is better than the worst
conversion for the second:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735: note: candidate 1: std::basic_ostream<char, _Traits>&
std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with
_Traits = std::char_traits<char>]
Domain.h:507: note: candidate 2: o& operator<<(o&, const Domain&)
[with o = std::ofstream]
make: *** [main.o] Error 1
Thank you all!
a2
推荐答案
aaragon写道:
aaragon wrote:
您好,有没有人对此错误有任何疑问?以及如何解决它?
这对我来说似乎微不足道,但对于编译器却没有。我在Ubuntu Linux系统上使用g ++
4.2:
// main()
...
std :: ofstream fout;
fout.open(" hello.out");
fout<< setfill('' - '')<< setw(20)<<" - "<< setfill('''')<< endl;
fout<<" ;你好; //这是第139行
...
main.cxx:89:从这里实例化
main.cxx: 139:错误:ISO C ++说这些都是模棱两可的,即使是
虽然第一个最差的转换比第二个最差的转换
更好:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735:注意:候选人1:std :: basic_ostream< char,_Traits>&
std :: operator<<(std :: basic_ostream< char,_Traits>& ,const char *)[with
_Traits = std :: char_traits< char>]
Domain.h:507:注意:候选人2:o& operator<<(o&,const Domain&)
[with o = std :: ofstream]
make:*** [main.o]错误1
Hello, does anyone have a clue about this error? and how to solve it?
It seems to be trivial to me, but not for the compiler. I''m using g++
4.2 on an Ubuntu Linux system:
// main()
...
std::ofstream fout;
fout.open("hello.out");
fout<<setfill(''-'')<<setw(20)<<"-"<<setfill('' '')<<endl;
fout<<"hello "; // this is line 139
...
main.cxx:89: instantiated from here
main.cxx:139: error: ISO C++ says that these are ambiguous, even
though the worst conversion for the first is better than the worst
conversion for the second:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735: note: candidate 1: std::basic_ostream<char, _Traits>&
std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with
_Traits = std::char_traits<char>]
Domain.h:507: note: candidate 2: o& operator<<(o&, const Domain&)
[with o = std::ofstream]
make: *** [main.o] Error 1
我没有看到任何Domain.h或者在你的代码中称为域名的类型。
V
-
请删除大写''A'在回复电子邮件时
我没有回复最热门的回复,请不要问
I don''t see any "Domain.h" or types called ''Domain'' in your code.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
9月26日,下午2:41,Victor Bazarov < v.Abaza ... @ comAcast.netwrote:
On Sep 26, 2:41 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
aaragon写道:
aaragon wrote:
您好,有没有人对这个错误有所了解?以及如何解决它?
这对我来说似乎微不足道,但对于编译器却没有。我在Ubuntu Linux系统上使用g ++
4.2:
Hello, does anyone have a clue about this error? and how to solve it?
It seems to be trivial to me, but not for the compiler. I''m using g++
4.2 on an Ubuntu Linux system:
// main()
...
std :: ofstream fout;
fout.open(" hello.out");
fout< ;< setfill('' - '')<< setw(20)<<" - "<< setfill('''')<< endl;
fout<<" hello" ;; //这是139行
...
// main()
...
std::ofstream fout;
fout.open("hello.out");
fout<<setfill(''-'')<<setw(20)<<"-"<<setfill('' '')<<endl;
fout<<"hello "; // this is line 139
...
main.cxx:89:从这里实例化
main.cxx:139:错误:ISO C ++说这些是模棱两可的,即使是
虽然最差的转换比最差的转换更好
转换对于第二个:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits /
ostream.tcc:735:注意:候选人1:std :: basic_ostream< char,_Traits>&
std :: operator<<(std :: basic_ostream< char,_Traits>&,const char *)[with
_Traits = std :: char_traits< char>]
Domain.h:507:注意:候选人2:o& operator<<(o&,const Domain&)
[with o = std :: ofstream]
make:*** [main.o]错误1
main.cxx:89: instantiated from here
main.cxx:139: error: ISO C++ says that these are ambiguous, even
though the worst conversion for the first is better than the worst
conversion for the second:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735: note: candidate 1: std::basic_ostream<char, _Traits>&
std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with
_Traits = std::char_traits<char>]
Domain.h:507: note: candidate 2: o& operator<<(o&, const Domain&)
[with o = std::ofstream]
make: *** [main.o] Error 1
我没有看到任何Domain.h或者在你的代码中称为域名的类型。
V
-
请删除大写''A'当通过电子邮件回复时
我没有回复最热门的回复,请不要问
I don''t see any "Domain.h" or types called ''Domain'' in your code.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
嗯,我重载了运算符<<产生我设计的类的输出。但编译器不应该从传递给运算符<< ????的类型中扣除这一点。为什么这个电话不明确????
Well, I overloaded operator<< to produce the output of a class that I
designed. But shouldn''t the compiler deduct this from the type being
passed to operator<<???? Why is it the call ambiguous????
aaragon写道:
aaragon wrote:
您好,有没有人对这个错误有所了解?以及如何解决它?
这对我来说似乎微不足道,但对于编译器却没有。我在Ubuntu Linux系统上使用g ++
4.2:
// main()
...
std :: ofstream fout;
fout.open(" hello.out");
fout<< setfill('' - '')<< setw(20)<<" - "<< setfill('''')<< endl;
fout<<" ;你好; //这是第139行
...
main.cxx:89:从这里实例化
main.cxx: 139:错误:ISO C ++说这些都是模棱两可的,即使是
虽然第一个最差的转换比第二个最差的转换
更好:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735:注意:候选人1:std :: basic_ostream< char,_Traits>&
std :: operator<<(std :: basic_ostream< char,_Traits>& ,const char *)[with
_Traits = std :: char_traits< char>]
Domain.h:507:注意:候选人2:o& operator<<(o&,const Domain&)
[with o = std :: ofstream]
make:*** [main.o]错误1
谢谢大家!
a2
Hello, does anyone have a clue about this error? and how to solve it?
It seems to be trivial to me, but not for the compiler. I''m using g++
4.2 on an Ubuntu Linux system:
// main()
...
std::ofstream fout;
fout.open("hello.out");
fout<<setfill(''-'')<<setw(20)<<"-"<<setfill('' '')<<endl;
fout<<"hello "; // this is line 139
...
main.cxx:89: instantiated from here
main.cxx:139: error: ISO C++ says that these are ambiguous, even
though the worst conversion for the first is better than the worst
conversion for the second:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
ostream.tcc:735: note: candidate 1: std::basic_ostream<char, _Traits>&
std::operator<<(std::basic_ostream<char, _Traits>&, const char*) [with
_Traits = std::char_traits<char>]
Domain.h:507: note: candidate 2: o& operator<<(o&, const Domain&)
[with o = std::ofstream]
make: *** [main.o] Error 1
Thank you all!
a2
a你的程序编译的最小版本并创建一个文件,在运行后
''你好'':
#include< fstream>
int main()
{
std :: ofstream fout;
fout.open(" hello.out");
fout<<" hello";
fout.close();
返回0;
}
您是否在代码中包含第一行?
a minimal version of your program compiles and creates a file contianing
''hello '' after running:
#include <fstream>
int main()
{
std::ofstream fout;
fout.open("hello.out");
fout<<"hello ";
fout.close();
return 0;
}
did you include the first line in your code?
这篇关于使用ofstream编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!