-2

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!

John Lui
  • 1,434
  • 3
  • 23
  • 37
  • 4
    Read the whole input and [split](http://stackoverflow.com/questions/236129/split-a-string-in-c) it. Also [indexOf()](http://stackoverflow.com/questions/651497/how-to-do-stdstring-indexof-in-c-that-returns-index-of-matching-string) and [substring()](http://www.cplusplus.com/reference/string/string/substr/) is a good choice. – Uma Kanth Aug 21 '15 at 17:17
  • it may help u http://stackoverflow.com/questions/236129/split-a-string-in-c – Shebin Koshy Aug 21 '15 at 17:26

1 Answers1

0

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;
}
melak47
  • 4,772
  • 2
  • 26
  • 37