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);
	if(!inFile)
	{
		cout << "Cannot open the file. Sorry!!!" << endl;
		return 0;
	}

	inFile.get(ch);
	while(!inFile.eof())
	{
		outFile.put((ch - 5));
		inFile.get(ch);
		


	}

	inFile.close();
	outFile.close();
	cout << "File decryption is done.\n";
	return 0;





}

Recommended Answers

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 \\

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.