I'm doing a homework assignment, but I have done most of the work and am only looking for some tutoring to get past this small portion of the program I have been tasked to write.
The program says that a filename of "numbers.txt" will be defaulted to if the user presses enter when prompted. I set this up as a string and had no problem getting the default value to work properly. My problem occurs when the user tries to create a file with an actual name. I try to infile.open, but it won't accept my variable I used to create the string.
I'm not sure if this makes sense, but hopefully my code will. Here goes nothing:
Expand|Select|Wrap|Line Numbers
- void fileName(){
- ifstream infile;
- cout<<"Please enter a name for your file: ";
- string x;
- getline(cin,x);
- if(x == "\0"){
- cout<<"Your filename will be numbers.txt";
- infile.open("nums.in");
- }
- else{
- cout<<"Your filename will be "<<x<<endl<<endl;
- infile.open();
- }
- }
Thanks...