hi
I'm trying to write/read from a file in c++. The function which writes to a file is as follows:
const char * EncQR = Extract_ClientPublicKey_Encrypt_QRcode(str, ClientCert_String);
ofstream myfile1;
myfile1.open("ram.txt");
if (myfile1.is_open())
{
myfile1 <<EncQR<<"\n";
}
else
cout<<"Unable to open file";
The previous code works fine, and write into a txt file. But the problem is with the next function, which tries to read from a file:
int _tmain(int argc, _TCHAR* argv[])
{
string line;
ifstream myfile1("ram.txt");
if (myfile1.is_open())
{
while(! myfile1.eof()) {
getline(myfile1, line);
std::cout << line << "\n\n";}
}
else cout << "Unable to open file";
getch();
myfile1.close();
return 0;
}
Where i keep getting "Unable to open file". I've tried another file consisting of a single line, and it was working. but with the "ram.txt" file, which consists of multiple lines, it doesn't work.
I even tried to copy the file into the directory in which my project is located, and still, didnt work.
Need help pleeeeease
Regards.