Hi all.
First off, cheers to the Cprogramming.com guys, I've tryed a couple of times to get into C++ with no sucess, but after a couple of hours here, I feel I am now on the road (Or at least I am in the car and the engine is running, now I'm just trying to find the map )
Anyway, I am trying to learn by reading some, then making simple programs as I go. Currently I am working on a program to take a CSV file from a server, copy it locally, remove unwanted lines and format the remaining lines into commands (For a batch file).
Here is the code I have so far:
What that should do so far is open a text document which contains the build number (Its the dynamic part of the path to the CSV file) and display it. It should ask if the buildname is correct and the user enters Y or N and the program continues accordingly. However, when I cout the N and Y vars they come up as '?' and '$' respectivley.Code:#include <iostream> #include <fstream> using namespace std; // So the program can see cout and endl int main() { int buildname; char bnamecorrect; char N = N; char Y = Y; int namedone = 0; /*Display welcome and current buildname*/ /*Getting data from file*/ while (namedone == 0){ ifstream a_file ( "buildname.txt" ); if ( !a_file.is_open() ) { // The file could not be opened cout<<"No build name found. Please enter below\n"; cin>>buildname; /*Close file for reading (Just in case)*/ a_file.close(); /*Open file for editing*/ ofstream a_file ( "buildname.txt" ); /*And write info*/ a_file<<buildname; /*Close it again*/ a_file.close(); } else { // Safely use the file stream a_file.close(); /*Open file and read build name*/ ifstream a_file ( "buildname.txt" ); a_file>>buildname; /*Output buildname and check if correct*/ cout<<"Current buildname is "<<buildname<<", is this correct? Y/N\n"; cin>>bnamecorrect; /*If buildname is not correct, get new name and add it to file*/ cout<<bnamecorrect<<"\n"<<N<<"\n"<<Y<<"\n"; if (bnamecorrect == N){ cout<<"Please enter new build name\n"; cin>>buildname; /*Open file for editing*/ ofstream a_file ( "buildname.txt" ); /*And write info*/ a_file<<buildname; namedone = 1; } else if (bnamecorrect == Y){ cout<<"Procceeding with buildname "<<buildname<<"\n"; namedone = 1; } else { cout<<"Please use Y or N\n"; } } } cout<<"Welcome to the test tool\n"; cout<<""; cin>>buildname; cin.get(); }
Anyone explain why they are doing that?
Thanks for your help - Linkjames
p.s. No doubt I am going about this all wrong. If I am doing something blatently wrong, I would also appreciate someone telling me so, and if possible, pointing me in the correct direction.