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
Post a Comment