错误发生在outFile.close; 不知道为什么会这样,但我会喜欢一些帮助。谢谢! 我对c ++有点新意,所以它可能是我忽略的非常简单的事情。
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
void what1();
int main()
{
return 0;
}
void what1()
{
int counter=20;
float num1=rand();
fstream infile;
ofstream outFile;
outFile.open("randomdata.txt");
if (!outFile)
{
cout << "File not open";
}
else
{
while (counter<=20)
{
num1=rand();
outFile<<num1<<endl;
counter++;
}
outFile<<num1;
outFile.close;
}
}