0

I am new to C, so my question may be stupid. I am sorry.

I get two integers on one line divided by space. For example 3 4. I can store them easily using this scanf("%d %d", &N, &M); to variables N and M. My question is: is it possible to do the same thing using cin and, if so, how? Or, how can I store these integers into two different variables using cin?

Tomas Nekvinda
  • 524
  • 1
  • 5
  • 15

2 Answers2

3
cin>>N>>M;

but this stuff is explained in the first chapters of any decent C++ book; keep in mind that a Q&A site like StackOverflow cannot be a replacement for a C++ manual.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
2

The whitespace character and a newline are stream dilimeters, so it will work exactly the same way with scanf as it does with std::cin.

int a, b;
std::cin  >> a >> b;
std::cout << a << b;

Input: 3 4
Output: 34

David G
  • 94,763
  • 41
  • 167
  • 253