cout<<"-Please enter the spacing:";
cin>>space;
cout<<"-Please enter a string of length<70:"<<endl;
getline(cin,s);
-----------------------------------------------------------------
when executeing,after i key in space=2,
the program show "-Please enter a string of length<70:"
then it stop,
why can't i continuing key in the string??
A little bit more context would be helpful, but if this is the
entire contents of your main, the program probably will not wait
for user input after the second prompt. None of the formatting
extractors (the >> operators) read trailing white space, so at
the very least, the '\n' at the end of the first line will still
be in the stream when you do the getline.
As a general rule, mixing reading with >> and getline doesn't
work too well. (The one exception is when you use getline to
read the remainder of the line you've partially parsed.) What
you probably want to do is something like:
std::cout << "-Please enter the spacing: " ;
std::cout.flush() ;
getline( line ) ;
std::istringstream s( line ) ;
if ( ! (s >> space >> std::ws) || s.get() != EOF ) {
// Error...
} else {
std::cout << "-Please enter a string of length < 70: " ;
std::cout.flush() ;
getline( line ) ;
// process string...
}