请教下是不是还要添加其它头文件才能使程序运行?

#include<fstream>
using namespace std;
int main(){
ifstream in("a.in");
ifstream out("a.out");
for(string str;getline(in,str);)
out<<str<<endl;
}
为什么程序放到VC6.0无法运行?程序中out是干嘛的?

慕尼黑8549860
浏览 50回答 2
2回答

拉莫斯之舞

#include <fstream>#include <string>using namespace std;int main() {ifstream in("a.in");ofstream out("a.out");for (string str; getline(in, str);)out << str << endl;}

至尊宝的传说

需要和ref对比着来说,out是返回值,使用ref前必须对变量赋值,out不用。&nbsp;out的函数会清空变量,即使变量已经赋值也不行,退出函数时所有out引用的变量都要赋值,ref引用的可以修改,也可以不修改。&nbsp;区别可以参看下面的代码:&nbsp;&nbsp;using System;&nbsp;class TestApp&nbsp;{&nbsp; static void outTest(out int x, out int y)&nbsp; {//离开这个函数前,必须对x和y赋值,否则会报错。&nbsp;  //y = x;&nbsp;  //上面这行会报错,因为使用了out后,x和y都清空了,需要重新赋值,即使调用函数前赋过值也不行&nbsp;  x = 1;&nbsp;  y = 2;&nbsp; }&nbsp; static void refTest(ref int x, ref int y)&nbsp; {&nbsp;  x = 1;&nbsp;  y = x;&nbsp; }&nbsp; public static void Main()&nbsp; {&nbsp;  //out test&nbsp;  int a,b;&nbsp;  //out使用前,变量可以不赋值&nbsp;  outTest(out a, out b);&nbsp;  Console.WriteLine("a={0};b={1}",a,b);&nbsp;  int c=11,d=22;&nbsp;  outTest(out c, out d);&nbsp;  Console.WriteLine("c={0};d={1}",c,d);&nbsp;  //ref test&nbsp;  int m,n;&nbsp;  //refTest(ref m, ref n);&nbsp;  //上面这行会出错,ref使用前,变量必须赋值&nbsp;  int o=11,p=22;&nbsp;  refTest(ref o, ref p);&nbsp;  Console.WriteLine("o={0};p={1}",o,p);&nbsp; }&nbsp;}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP