So the teacher has posed this assignment:
You have been hired by the United Network Command for Law Enforcement, and you have been given files containing null cyphers you have to decrypt.
So for the first file given (as an example), every other letter is correct (ie: 'hielqlpo' is hello (assuming you start with the first letter). My first question is, how do I read in a file? The document is on my desktop in a folder and the file is named document01.cry. I'm not sure the command I need to put that file into the program.
I'm also not overly sure how to grab a letter and skip a letter, but honestly I want to tinker with that before I post that question! So for now...my question is as stated in the title: How do you grab a file for reading in C++?
If it makes a difference (As I'm sure it does), I'm using Visual C++ 2008 Express Edition (because it's free and I like it! I've also attached what I have so far, please keep in mind it's -very- basic...and I added the getchar();
at the end so when it does run properly, the window stays open so I can see it (as Visual Express tends to close the window as soon as it's done running.)
The code so far:
#include<iostream>
using namespace std;
int main()
{
while (! cin.eof())
{
int c = cin.get() ;
cout.put(c) ;
}
getchar();
}
PS: I realize that this code grabs and puts out every character. For now that's fine, once I can read in the file I think I can tinker with it from there. I'm also poking at a book or two I have on C++ to see it anything pops up and screams "Pick me!" Thanks again!
EDIT:: Also curious, is there a way to input the file you want? (I.e.:
char filename;
cout << "Please make sure the document is in the same file as the program, thank you!" << endl << "Please input document name: " ;
cin >> filename;
cout << endl;
ifstream infile(filename, ios::in);
This code doesn't work. It shoots back an error saying the char can't be converted to a const char *. How can this problem be fixed?
EDIT 2: Never mind about said part 2, I found it out! Thanks again for the assistance!