Basically I have my code lined out to what I thought would work, but I guess I dont understand fstream completely. I thought I could fstream and inFile to this txt, but I cant get it to compile.
Error is:
encryption.cpp: In function ‘int main()’:
encryption.cpp:18: error: no matching function for call to ‘std::basic_fstream<char, std::char_traits<char> >::basic_fstream(std::string&, const std::ios_base::openmode&)’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/fstream:795: note: candidates are: std::basic_fstream<_CharT, _Traits>::basic_fstream(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/fstream:782: note: std::basic_fstream<_CharT, _Traits>::basic_fstream() [with _CharT = char, _Traits = std::char_traits<char>]
Any tips would be much appreciated
Edit: removed the part where I tried to initiliaze a fileName, it wasnt needed and caused an error
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 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string fileName, encrypt;
char ch;
// Ask the user to enter the name of the unencrypted file
cout << "Enter the name of the file to encrypt: ";
cin >> fileName;
cout << "Enter name for encrypted file: ";
cin >> encrypt;
fstream inFile(fileName, ios::in);
if (!inFile)
{
cout << "Error opening file \"" << fileName << "\".\n";
return 0;
}
fstream outFile(encrypt, ios::out);
while (!inFile.fail())
{
inFile.get(ch);
ch += 10;
outFile << ch;
}
inFile.close();
outFile.close();
return 0;
}
| |