hi ia m trying to make a program to create text files from user input, but every time the return key is pressed it stops geting user input and writes the text to the file.i want it to just create a new line but i dont know how to, can somebody help? could you also tell me how to get input to name the file, thanks in advance.
With getline() you could specify which character will stop the input: getline(cin,text,'\0'); should get until a '\0' char is found (which could probably never happen)
Try this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int newfile()
{
system("cls");
cout <<"\t\t-------------------------------------" <<endl;
cout <<"\t\t| NEW FILE |" <<endl;
cout <<"\t\t-------------------------------------" <<endl;
cout <<"\tPress Ctrl+B to break input"<<endl;
getline(cin,text,'\2');
if(! outfile)
{
cout <<"error writing to file" <<endl;
return -1;
}
outfile << text <<endl;
outfile.close();
}
And of course you will have to press enter after the breaking character