Not sure why it won't compile. Usually gives me errors and highlights the lines that need work. When I try to compile it does not highlight anything. Just prints a lot of messages. Even messages for line 568, which does not exist in this code.
system("PAUSE");
return EXIT_SUCCESS;
}
void get_file (char in_file, char out_file, ifstream& fin, ofstream& fout)
{
cout << "What is the name of the file containing data to be analyzed?"
cin >> in_file;
fin.open(in_file);
if (fin.fail())
{
cout << "Input file failed.\n.";
exit(1);
}
cout << "What is the name of the file where you would like to store data? \n"
cin >> out_file;
fout.open(out_file);
if (fout.fail())
{
cout << "imput file failed.\n.";
exit(1);
}
}
The purpose of the function is to get the variables values from the user (the array), and use them to open the files. I am not trying to return anything, nor pass the chars with values, but have the chars defined as files in the function by the user and have the files opened(I think?). Not sure were I am going wrong. I changed the arguments into arrays.
system("PAUSE");
return EXIT_SUCCESS;
}
void get_file (char in_file[], char out_file[], ifstream& fin, ofstream& fout)
{
cout << "What is the name of the file containing data to be analyzed?"
cin >> in_file;
fin.open(in_file);
if (fin.fail())
{
cout << "Input file failed.\n.";
exit(1);
}
cout << "What is the name of the file where you would like to store data? \n"
cin >> out_file;
fout.open(out_file);
if (fout.fail())
{
cout << "imput file failed.\n.";
exit(1);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
void get_file (ifstream fin, ofstream fout)
{
char in_file[40], out_file[40];
cout << "What is the name of the file containing data to be analyzed?\n"
cin >> in_file;
fin.open(in_file);
if (fin.fail())
{
cout << "Input file failed.\n";
exit(1);
}
cout << "What is the name of the file where you would like to store data?\n"
cin >> out_file;
fout.open(out_file);
if (fout.fail())
{
cout << "imput file failed.\n";
exit(1);
}
}
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
void get_file(ifstream &fin, ofstream &fout);
/* to get, open, and test the files for input and output data.*/
int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;
get_file(fin, fout);
system("PAUSE");
return EXIT_SUCCESS;
}
void get_file (ifstream &fin, ofstream &fout)
{
char in_file[40], out_file[40];
cout << "What is the name of the file containing data to be analyzed?\n";
cin >> in_file;
fin.open(in_file);
if (fin.fail())
{
cout << "Input file failed.\n";
exit(1);
}
cout << "What is the name of the file where you would like to store data?\n";
cin >> out_file;
fout.open(out_file);
if (fout.fail())
{
cout << "imput file failed.\n";
exit(1);
}
}
Ok. Lines 7 and 22 you should be passing the ifstream and ofstream by reference. You had it correct on an earlier edit. Also you were missing semicolons at on lines 25 and 33. Other than that it looks good.
Thanks, I changed those things, but it is still not compiling. The strange thing to me is that it is not highlighting anything to show were the errors are. It simply prints numerous messages and does not run. Must all type ifstream and ofstream be used as reference in functions?
system("PAUSE");
return EXIT_SUCCESS;
}
void get_file (ifstream &fin, ofstream &fout)
{
char in_file[40], out_file[40];
cout << "What is the name of the file containing data to be analyzed?\n";
cin >> in_file;
fin.open("in_file");
if (fin.fail())
{
cout << "Input file failed.\n";
exit(1);
}
cout << "What is the name of the file where you would like to store data?\n";
cin >> out_file;
fout.open("out_file");
if (fout.fail())
{
cout << "Input file failed.\n";
exit(1);
}
}
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
void get_file(ifstream &fin, ofstream &fout);
/* to get, open, and test the files for input and output data.*/
int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;
get_file (fin, fout);
system("PAUSE");
return EXIT_SUCCESS;
}
void get_file (ifstream &fin, ofstream &fout)
{
char in_file[40], out_file[40];
cout << "What is the name of the file containing data to be analyzed?\n";
cin >> in_file;
fin.open("in_file");
if (fin.fail())
{
cout << "Input file failed.\n";
exit(1);
}
cout << "What is the name of the file where you would like to store data?\n";
cin >> out_file;
fout.open("out_file");
if (fout.fail())
{
cout << "Input file failed.\n";
exit(1);
}
}
In lines 27 and 35 the in_file and out_file should not be in quotations. This will cause the open function to actually try to open a file called in_file or out_file. Even with those errors it still compiles on DevC++. What compiler are you using?