关于文件的读取问题

nimingzhe2008 2011-05-26 07:40:56
我想将文件abc.txt读取并输出到屏幕上,代码如下:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void main()
{
ifstream in;
in.open("C:\Useres\dell\Documents\Visual Studio 2010\Projects\p254 2\abc.txt");
string s;
in>>s;
cout<<s;
system("pause");
}

可以编译,但没有输出
...全文
134 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
nimingzhe2008 2011-06-03
  • 打赏
  • 举报
回复
怎么改配置属性啊[Quote=引用 10 楼 sunwenhua168 的回复:]


将配置属性中的unicode改成多字节符
[/Quote]
A28496647 2011-05-31
  • 打赏
  • 举报
回复
用校园网的孩子你们伤不起,不要老是google,google,google根本就打不开。
downmooner 2011-05-30
  • 打赏
  • 举报
回复
也许你文件最开始2字节是unicode的标识 0xff 0xfe
情意书生 2011-05-30
  • 打赏
  • 举报
回复
用\\后还是打不开,后来把文件换了位置,在用\\就能打开了。但有乱码,理论上应该出现123456,实际上却出现锘?23456。怎么办?
将配置属性中的unicode改成多字节符
nimingzhe2008 2011-05-30
  • 打赏
  • 举报
回复
用\\后还是打不开,后来把文件换了位置,在用\\就能打开了。但有乱码,理论上应该出现123456,实际上却出现锘?23456。怎么办?
嘻嘻嘻_ 2011-05-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 sanshao1314 的回复:]
双\\
[/Quote]

+1
Freedom 2011-05-26
  • 打赏
  • 举报
回复
双\\
feimashenhua 2011-05-26
  • 打赏
  • 举报
回复
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void main()
{
ifstream in;
in.open("./abc.txt");
string s;
in>>s;
cout<<s;
system("pause");
}

刚才试了一下,可以输出呀。
feimashenhua 2011-05-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 vcf_reader 的回复:]

文件中没有内容?
[/Quote]建议判断一下ifstream in,是否打开

vcf_reader 2011-05-26
  • 打赏
  • 举报
回复
文件中没有内容??
c_losed 2011-05-26
  • 打赏
  • 举报
回复

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void main()
{
ifstream in;
in.open("C:\\Useres\\dell\\Documents\\Visual Studio 2010\\Projects\\p254 2\\abc.txt");
string s;
in>>s;
cout<<s;
system("pause");
}
xspace_time 2011-05-26
  • 打赏
  • 举报
回复
太复杂了,直接
#include<stdlib.h>
main()
{
system("type C:\\abc.txt");
}
bargio_susie 2011-05-26
  • 打赏
  • 举报
回复
	if (in.fail())
{
cout << "open file fail" << endl;
}


先加这段看是不是没找到要打开的文件

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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