i am writing a decryption program that reads a file from another project solution and decrypts it then writes it to a new file in its own project folder. For some reason when i try and read the file in the program says that file doesn't exist. Im pretty sure its not the path because i select the file i want to take the information from and i got its path from its properties. I dont know what might be wrong. Here is my code:

#include <iostream>
#include <fstream>
using namespace std;

int main()
	const int SIZE = 61;
	char fileName[SIZE];
	fstream inFile ("C:\Users\Chris\Documents\Visual Studio 2008\Projects\ChrisCaldwell_Ch12_Encrypt\ChrisCaldwell_Ch12_Encrypt\nameEncrypt.txt", ios::in | ios::out);
	char ch;

	ofstream outFile("newName.txt");

	/*cout << "Please give the name for the file to be decrypted?"; 
	cin >> fileName;*/

	//inFile.open("C:\Users\Chris\Desktop\ChrisCaldwell_Ch12_Encrypt\ChrisCaldwell_Ch12_Encrypt\nameEncrypt.txt", ios::in);
		cout << "Cannot open the file. Sorry!!!" << endl;
		return 0;

		outFile.put((ch - 5));


	cout << "File decryption is done.\n";
	return 0;


Recommended Answers

You can just use the forward slash key instead; it will work on all the common desktop operating systems.


Jump to Post

All 2 Replies

In string constants enclosed in quotes, the backslash\ is used as an escape sequence so you can put in characters that you normally couldn't type into the string, like \" or \' so you have to use the escape sequence for the \ in the file name which is just \\