Goto skipping cin

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;
}
The problem using getline(...) in combination with the operator>> is that the operator>> leaves a newline in the stream. The getline(...) after the operator>> consumes this newline and returns an empty string.

You can solve that problem when using getline(...) in both cases cin>>name; and cin>>rename;
Topic archived. No new replies allowed.