Okay, so I'm trying to write encrypted text to a file.
For some reason, I am getting a not declared in this scope compile error.
Here's my encryption.cpp file:
#include <iostream>
#include <fstream>
#include <string>
class encrypt{
public:
static void cryptText(std::string newpass)
{
int x = newpass.size();
int output[x -1];
for(int i = 0; i <= x -1; i++)
{
output[i] = (int)newpass[i];
std::cout << char(output[i] + x);
//Here I am trying to write output onto the file. For some reason, though,
//I get the error.
myfile.open ("passwords.thaddeus");
myfile << output << std::endl;
myfile.close();
}
std::cout << std::endl;
}
};
I have looked at the cplusplus.com documentation for Input/Output with files. I copied their example program into Code::Blocks, and it worked perfectly. But when I try it, I get the error. It's strange because I included .
myfile
you got out of bounds array access atoutput[i]+x
with i == 0 - Sergeyusing namespace std;
which is bad so without that you need to dostd::ofstream myfile;
. - Shafik Yaghmour