关于读取文件的问题

Tanghla 2007-04-03 04:28:08
文件内容如下:
this is line 1!
this is line 2!
this is line 3!


想问怎样将这个文件中的3行内容存放到字符数组(一维数组就行,如char buf[200])中去呢?
...全文
160 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
w60014489 2007-04-03
  • 打赏
  • 举报
回复
ifstream in("a.txt");
char buf[200];
memset(buf,0,200);
in.read(buf,200);
in.close;
w60014489 2007-04-03
  • 打赏
  • 举报
回复
ifstream in("a.txt");
char buf[200];
memset(buf,0,100);
in.read(buf,200);
in.close;
Estfania 2007-04-03
  • 打赏
  • 举报
回复
fstream infile("a.txt");
string line;
vector<stirng> linevec;
while(getline(infile, line, '\n'))
{
linevec.push_back(line);
}
warfee2006 2007-04-03
  • 打赏
  • 举报
回复
readline()函数 按行读出
hellox 2007-04-03
  • 打赏
  • 举报
回复
getline()
+
for
taodm 2007-04-03
  • 打赏
  • 举报
回复
for循环呀
Tanghla 2007-04-03
  • 打赏
  • 举报
回复
能说具体点吗,我现在用fgets(),但只能拿到一行。。。。求提示。。
ouyh12345 2007-04-03
  • 打赏
  • 举报
回复
CStdioFile::ReadString
weijiangshanwww 2007-04-03
  • 打赏
  • 举报
回复
用函数getline()

64,637

社区成员

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

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