C
carmelo
Hi! I need to read and store data from a file, but I don't the name of
it; Is this code correct and is there a better way to do this thing??
int main()
{
cout << " type file name:"
char * name;
cin >> name;
ifstream indata;
int num1; // variables for input values
int num2;
int num3;
indata.open(name); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
indata >> num1;
indata >> num2;
indata >> num3;
}
it; Is this code correct and is there a better way to do this thing??
int main()
{
cout << " type file name:"
char * name;
cin >> name;
ifstream indata;
int num1; // variables for input values
int num2;
int num3;
indata.open(name); // opens the file
if(!indata) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
exit(1);
}
indata >> num1;
indata >> num2;
indata >> num3;
}