formatted input - What's the C++ version of scanf? -


for example...

char* foo; scanf("%[^\n\r]", foo); 

how can in c++, without including c libraries?

the equivalent have posted [aside fact char *foo without allocation of memory, lead writing either null or random location in memory] be

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

but more complex cases, read multiple items, either cin >> x >> y >> z; or std::getline(std::cin, str); std::stringstream ss(str); ss >> x >> y >> z; - or combination thereof.

but c-code valid valid in c++ too. it's not "right" solution, not wrong either.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -