关于ofstream
#include<iostream>
#include<cstdlib>
#include<ctime>
#include"vector.h"
#include<fstream>
int main()
{
ofstream fout;
。。。。。。。。。。。。。。
fout.open("a.txt") fout<<"After"<<steps<<"steps,the subject""has the following location:\n";
fout<<result<<endl;
result.polar_mode();
fout<<"or\n"<<result<<endl;
fout<<"Average outward distance per step= "
<<result.magval()/steps<<endl;
steps=0;
result.set(0.0,0.0,112);
cout<<"Enter target distance(q to quit):";
}
运行以后就有错了E:\C++学习\1131\randwalk.cpp(8) : error C2065: 'ofstream' : undeclared identifier
E:\C++学习\1131\randwalk.cpp(8) : error C2146: syntax error : missing ';' before identifier 'fout'
E:\C++学习\1131\randwalk.cpp(8) : error C2065: 'fout' : undeclared identifier
E:\C++学习\1131\randwalk.cpp(31) : error C2228: left of '.open' must have class/struct/union type
E:\C++学习\1131\randwalk.cpp(33) : error C2146: syntax error : missing ';' before identifier 'fout'
E:\C++学习\1131\randwalk.cpp(33) : error C2297: '<<' : illegal, right operand has type 'char [6]'
E:\C++学习\1131\randwalk.cpp(36) : error C2297: '<<' : illegal, right operand has type 'char [4]'
E:\C++学习\1131\randwalk.cpp(38) : error C2297: '<<' : illegal, right operand has type 'char [36]'
执行 cl.exe 时出错.
1131.exe - 1 error(s), 0 warning(s)
我就是给以前可以运行的程序加了一点红色的部分,还有把后面的cout改为fout,大家给看,本是想把这个程序的运行结果输出到a.txt,中,这个文件就在工程文件夹里面放着。