I have been recently going through the tutorials that your site offers. I decided to expand on one of the tutorials. This one to be precise, http://www.cprogramming.com/tutorial/lesson10.html and created the following program from this code.
It's a relatively simple program but in the last if statement when I try to make it possible for users to be able to enter text of there own there is a small problem. They can only seem to enter words such as "c_programming" and "nexus" any text with spaces or captials cuts out after the first letter.Code:#include<iostream>
#include <fstream>
using namespace std;
int main()
{
cout<<"This is a simple C++ program that writes text to a .txt file.\n Choose one of the following tasks to perform:\n";
int selection;
char str[10];
char filetext;
cout<<"1. Create blank text file or delete replace current file\n";
cout<<"2. Write some preprogrammed text into the text file.\n";
cout<<"3. Write your own text into the text file\n";
cout<<"Enter your option: \n";
cin>>selection;
cin.ignore();
if (selection == 1)
{
// load function for task 1
cout<<"You chose option 1\n";
ofstream a_file ( "example.txt" );
a_file.close();
}
else if(selection == 2)
{
// load function for task 2
cout<<"You chose option 2\n";
ofstream a_file ( "example.txt" );
a_file<<"Here is some predesigned text. Pretty cool huh!";
a_file.close();
}
else if(selection == 3)
{
// load function for task 3
cout<<"You chose option 3\n";
ofstream a_file ( "example.txt" );
cout<<"Please enter some text: ";
cin>> filetext;
a_file<<filetext;
a_file.close();
cin.ignore();
}
cin.get();
}
Can anyone help me make it so that all text will work and is it possible to make it change the name of the file as well.