Why do I get an infinite loop for the switch? And how do I save to a sub folder like: \saves\my_file.txt CODE: // Test-3.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <fstream> #include <string> using namespace std; //functions int write_file() { string text; string file_name; string ffile_name; cout<<"Please write your text: "; getline(cin,text); getline(cin,text); cout<<"\nEnd Text\n\nThank you.\n\nPlease enter your file name: "; getline(cin,file_name); ffile_name.append(file_name); ffile_name.append(".txt"); cout<<"\nEnd File Name\n\nThank you.\n\nWriting "<<text<<" to "<<ffile_name<<""; ofstream myfile; myfile.open (ffile_name); myfile << text; myfile.close(); cout<<"\n\nEnd"; return 0; } int read_file() { string file_name; string text; cout<<"\nPlease enter the file name you wish to read: "; getline(cin,file_name); getline(cin,file_name); file_name.append(".txt"); ifstream myfile (file_name); if (myfile.is_open()) { cout<<"\n\nData in "<<file_name<<":\n"; while ( myfile.good() ) { getline (myfile,text); cout << text << endl; } myfile.close(); } cout<<"\n\nEnd"; return 0; } //int vars int choice; //main int main() { while(0==0) { cout<<"\nEnter the number of your choice from the list below."; cout<<"\n1. Read File"; cout<<"\n2. Write File"; cout<<"\n"; cin>>choice; if(isdigit(choice)==0) { switch(choice) { case 1: read_file(); break; case 2: write_file(); break; } } else { cout<<"\nError"; } } } Thank you.
by while function you will get infinite loop and for up site you declare file extension so your file would be save when program will execute.
Please use a better translator that outputs standard English. What you have said here looks like monkeys dancing on your keyboard.