c++ - using getline to pass a string to an object without using an extra string variable -


so question simple (i hope). have class constructor looks this:

constructor(string szname) 

the string holding name; may more 1 part. john, john smith, john h smith, must valid inputs. know following:

std::string input;  getline(cin, input); myclass foo(input); 

and work fine. there anyway me directly send getline input constructor?

thank in advance.

well, if you're fine making function, this:

std::string readline() {     std::string input;     getline(cin, input);     return input; } 

and initialize class so:

myclass foo(readline()); 

Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -