If I have input like this,
apple+banana=3
And I want to store apple
in one string and banana
in another string and 3
in an integer, how can I do it? How can I skip those +
and =
signs? Thanks!
If I have input like this,
apple+banana=3
And I want to store apple
in one string and banana
in another string and 3
in an integer, how can I do it? How can I skip those +
and =
signs? Thanks!
std::getline
takes an optional delimiter as a third argument, so you could do something like:
#include <iostream>
#include <string>
int main() {
std::string a, b;
int c;
std::getline(std::cin, a, '+');
std::getline(std::cin, b, '=');
std::cin >> c;
}