I am trying to pass file names as formal parameters to a function in a separate .cpp file where the files will be opened and processed. I am able to open the files from within main, but would like to break that out into the separate function. I am pretty new to C++, so thanks in advance for your patience.
I am getting compile errors on this line of main():
|
openFilesForEncrypt(ifstream plainTextFile, ofstream cipherFile);
| |
The compile errors are:
Expected primary-expression before 'plainTextFile'
Expected primary-expression before 'cipherFile'
Here is the code snippet from main():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include "a06headerDylanVance.h"
int main()
{
//variables
char choice;
int shift;
string plainTextFile;
string cipherFile;
// a bunch of user input not relevant (I think)
switch (choice)
{
case 'e':
cout << "Please tell me the name of the file to encrypt: ";
cin >> plainTextFile;
cout << endl << "Please tell me the name of the plaintext file"
" to write: ";
cin >> cipherFile;
openFilesForEncrypt(ifstream plainTextFile, ofstream cipherFile);
encryptCaesar(shift); // stub
break;
case 'd':
decryptCaesar(shift); // stub
break;
default:
cout << "Something is amiss. Exiting program." << endl;
break;
}
| |
Here's how the Prototype looks in the .h file:
|
bool openFilesForEncrypt(ifstream & plainTextFile, ofstream & cipherFile);
| |
This compiles without error.
The called function in the 2nd .cpp file also has errors on compile with these two lines:
1 2
|
inFile.open(plainTextFile.c_str());
outFile.open(cipherFile.c_str());
| |
The error is:
'struct std::basic_ifstream<char, std::char_traits<char> >' has no member named 'c_str'
Here's how the function being called in the 2nd .cpp file looks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include "a06headerDylanVance.h"
bool openFilesForEncrypt(ifstream & plainTextFile, ofstream & cipherFile)
{
//bool openPlainTextFile = true;
//bool openCipherFile = true;
ifstream inFile;
ofstream outFile;
inFile.open(plainTextFile.c_str());
outFile.open(cipherFile.c_str());
//this function is nowhere near complete... just trying to open the files at this point.
return 0;
}
void encryptCaesar(int shift)
{
cout << "encryptCaesar(shift) function" << endl; // stub
cout << shift;
}
| |
Thanks again for taking the time to look at this.
-dtv