谁来帮我解决一下

sunskyland 2007-03-07 02:01:19
有一个程序
//------------------------------------------------------------------------

#include<fstream>
using namespace std;

//------------------------------------------------------------------------

int main()
{
ifstream in("a.txt");
ofstream out("b.txt");
for(string str;getline(in,str);)
out<<str<<endl;
return 0;
}
//------------------------------------------------------------------------

目的是将文件a.txt拷贝为b.txt。但是我在C++builder6中编译通过了,但是在VS2005中死活报错,谁来帮我说明一下呢?
...全文
313 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyu2202863 2007-06-26
  • 打赏
  • 举报
回复
int main()
{
ifstream in("a.txt");
ofstream out("b.txt");
for(string str;getline(in,str);)
out<<str<<endl;
return 0;
}
============>稍稍改下

int main()
{
ifstream in("a.txt");
ofstream out("b.txt");

string str;
while(getline(in,str))
out<<str<<endl;
return 0;
}
星羽 2007-06-26
  • 打赏
  • 举报
回复
out << in.rdbuf();
huang3407 2007-06-26
  • 打赏
  • 举报
回复
return 0;为什么要返回0,为什么不返回1
tigerweichao 2007-06-26
  • 打赏
  • 举报
回复
呵呵,大家稍安毋躁,只要加一行
#include<string>
就行了
honghongbp 2007-06-26
  • 打赏
  • 举报
回复
我 也遇到同样的问题啊,怎么解决啊?
zwh37333 2007-03-07
  • 打赏
  • 举报
回复
好像是string 类型没有声明
Shakugan_No_Shana 2007-03-07
  • 打赏
  • 举报
回复
int main()
{
ifstream in("a.txt");
ofstream out("b.txt");
for(string str;getline(in,str);out<<str<<endl);
}

不要return 0;返回看看呢.
sunskyland 2007-03-07
  • 打赏
  • 举报
回复
把str的定义放到for循环外面试了。
包含了预处理文件 stdafx.h。
但是都不能解决问题拉
sunskyland 2007-03-07
  • 打赏
  • 举报
回复
这是书上的一个例题
我试一试
sunskyland 2007-03-07
  • 打赏
  • 举报
回复
getline找不到标识符
呵呵
奇怪
jackadandyyang 2007-03-07
  • 打赏
  • 举报
回复
报什么错误啊?说清楚啊!我才好解决啊!
taodm 2007-03-07
  • 打赏
  • 举报
回复
不要那么复杂嘛。
out << in.rdbuf();即可。
www_adintr_com 2007-03-07
  • 打赏
  • 举报
回复
你不会是没包含预处理文件 stdafx.h 吧?
intuition444 2007-03-07
  • 打赏
  • 举报
回复
把str的定义放到for循环外面试试。
我在vc6下编译没问题

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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