Goto skipping cin

Hi, I'm kinda new to c++ and programming in general.
I'm trying to make a program that simply makes u create a text file.
In this first part I'm trying to make the user choose the name and if he wants to change it.
Now I have to problems:
1) What can I use instead of cin>>name in order to allow the user to use spaces?
2) I tried with getline, but when the user choose to rename the file with the goto function, it skips the command and doens't allow the user to rename it
With cin I don't have this problem but if I use it the user won't be able to use spaces.
That's the program (sorry but the indentation disappeared here):

#include <iostream>
using namespace std;
int main()

{
string name, rename;
cout<<"-------------------------";
cout<<"\nText file creator/editor";
cout<<"\n-------------------------\n";
renaming:
cout<<"\nName of the file: ";
cin>>name;
cout<<"\nThe file has been renamed ["<<name<<"].";
answer:
cout<<"\nDo you want to edit it? (y/n): ";
cin>>rename;
if (rename=="y") goto renaming;
else if (rename=="n") cout<<"\nOk.";
else
{
cout<<"[The answer is incorrect]\nUse y/n\n";
goto answer;
}
system ("PAUSE");
return 0;
}

Thanks in advance.
Last edited on
The stream either got too many character or broke, you need to add this before your goto answer line:

1
2
cin.clear();
std::cin.ignore(32767, '\n');


The first line will clear the error - "fix" the stream.
The second line will ignore 32767 characters or less worth of input until it reaches the '\n' or newline character (which is definitely in the stream since the user had to press "enter" to give the input that broke the stream).
Topic archived. No new replies allowed.