菜鸟问题

混混谔谔的十年 2003-12-03 11:05:21
#include "stdafx.h"

#include "download.h"

#include "fstream.h"
#include <vector>
using namespace std;



int main()
{
ifstream in("d:\\temp.txt");
in.seekg(1,ios::beg);
cout << in.rdbuf() << endl;
return 0;
}

在vc6下编译,却说ifstream 有二义性,请问为甚么,如何解决
...全文
52 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
fierygnu 2003-12-03
  • 打赏
  • 举报
回复
1、vector中包含了其他头文件,其中有ifstream的定义,是定义在std名字空间的。
2、#include "fstream.h"中定义了ifstream,定义在缺省的名字空间。
3、用了using namespace std后,两个ifstream就有了二义性。
ambition2005 2003-12-03
  • 打赏
  • 举报
回复
#include <fstream>
#include <vector>
#include<iostream>
using namespace std;



int main()
{
ifstream in("d:\\temp.txt");
in.seekg(1,ios::beg);
cout << in.rdbuf() << endl;
return 0;
}
这样些就对,那为什么楼主的那个会有二义性呢?
leyt 2003-12-03
  • 打赏
  • 举报
回复
#include "stdafx.h"
#include "download.h"
#include <fstream>
#include <vector>
using namespace std;
int main()
{
ifstream in("d:\\temp.txt");
in.seekg(1,ios::beg);
cout << in.rdbuf() << endl;
return 0;
}
heguobaoceo 2003-12-03
  • 打赏
  • 举报
回复
#include <fstream>
#include <vector>
#include<iostream>
using namespace std;



int main()
{
ifstream in("d:\\temp.txt");
in.seekg(1,ios::beg);
cout << in.rdbuf() << endl;
return 0;
}
liem 2003-12-03
  • 打赏
  • 举报
回复
仅从现在的程序来看,也可以去掉using namespace std;这一句。估计是在namespace std中对ifstream也有定义。
如果用#include <fstream>,还要加入#include <iostream>否则cout不能用。当然此时要用using namespace std;
heguobaoceo 2003-12-03
  • 打赏
  • 举报
回复
是咯
<fstream>是库函数
你不应该定义为"fstrema.h";
我发现好多的人都出现这中问题咯
thuers 2003-12-03
  • 打赏
  • 举报
回复
hanyixin 2003-12-03
  • 打赏
  • 举报
回复

当然了,也要 using namespace std;

hanyixin 2003-12-03
  • 打赏
  • 举报
回复

用:

#include <fstream>

就可以了。

bluesmile979 2003-12-03
  • 打赏
  • 举报
回复
#include <fstream>
Rossonero 2003-12-03
  • 打赏
  • 举报
回复
我刚开始看C++,就留了个fstream.h,在vc6下无任何问题.
//#include "stdafx.h"

//#include "download.h"

#include "fstream.h"
//#include <vector>
//using namespace std;



int main()
{
ifstream in("d:\\temp.txt");
in.seekg(1,ios::beg);
cout << in.rdbuf() << endl;
return 0;
}
mufengqing 2003-12-03
  • 打赏
  • 举报
回复
扫嘎

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧