C++找不到哪里出错了 高手帮忙看看

来源:百度知道 编辑:UC知道 时间:2024/09/24 01:54:20
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <time.h>
#include <string>
#include <cmath>

using namespace std;

void getFileName(ofstream &out);
void getMinMaxValue(int &min, int &max);
void getQuantity(int &qty);
void generateRandom(ostream &out, int qty, int min, int max);

int main(int argc, char *argv[])
{
ofstream out;
int min, max, qty;
srand(time(NULL));
getFileName(out);
getMinMaxValue(min, max);
getQuantity(qty);
generateRandom(out, qty, min, max);
system("PAUSE");
return EXIT_SUCCESS;
}

void getFileName(ofstream &out)
{
ifstream in;
char name[255];
cout<<"Please enter a file name: ";
cin>>name;
in.open(name);
if(in.fail())
{

void getFileName(ofstream &out)
{
ifstream in;
char name[255];
cout<<"Please enter a file name: ";
cin>>name;
in.open(name);
if(in.fail())
{
char ans[100] = {0};/*内存需要初始化*/
bool again = true;
in.clear();
in.close();
cout<<"File already exists. Do you want to (O)verwrite, (A)ppend, or (Q)uit: ";
fflush(stdin);/*这句话一道这边来*/
cin.getline(ans,100);

while(again)
switch(toupper(ans[0]))
{
case 'O' : out.open(name);
again = false;
break;

case 'A' : out.open(name, ios::app);
again = false;
break;

case 'Q' : exit(1);

default : cout<<"Unknown command. Please re-enter"<<endl;
system("pause");
}
}
else
{
in.clear();
in.close();
in.open(name);
}
}