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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -