string buffer problems/inputting on same line

Hey, worlds worst programmer here. I have a question on using the string buffer as I'm having problems inputting two numbers on the same line. Now, with namespace std, I wouldn't have that problem. As I would usually use just the
cin >> x >> y;
cout << x << y;

And there would be no problem. Here is the code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  // Lab 3, Change
// Programmer: Jesse Burns
// Editor(s) used: JNotePad
// Compiler(s) used: VC++ 2010 Express

// The necessary C++ file library
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <string>
using std::string;

#include <cstdlib>

int main()
{

      // Jesse Burns, Lab 3
  cout << "Lab 3, Change\n";
  cout << "Programmer: Jesse Burns\n";
  cout << "Editor(s) used: JNotePad\n";
  cout << "Compiler(s) used: VC++ 2010 Express\n";
  cout << "File: " << __FILE__ << endl;
  cout << "Compiled: " << __DATE__ << " at " << __TIME__ << endl << endl;

  string buf;
  string buf1;
  string buf2;
  int x;
  int y;

  cout << "Enter two numbers on the same line and they will be outputted."<<endl;
  cin >> buf1 >> buf2;
  cin >> buf; x = atoi(buf.c_str());
  cin >> buf; y = atoi(buf.c_str());

  cout << "The output is "<< x << " and " << y << endl;


}


Any pointers to help me out with this? Thanks. I'm trying to work on my programming while being forced to watch the Superbowl from my family.
The problem is that you ask for input for buf1 and buf2, but then you try to get more input for buf when you don't really need to.
29
30
31
32
33
34
35
36
37
38
39
40
//string buf; // Not needed
string buf1;
string buf2;
int x;
int y;

cout << "Enter two numbers on the same line and they will be outputted."<<endl;
cin >> buf1 >> buf2;
/*cin >> buf; x = atoi(buf.c_str());
cin >> buf; y = atoi(buf.c_str());*/
x = atoi(buf1.c_str());
y = atoi(buf2.c_str());

In any case, though, what's wrong with a simple cin >> x >> y;?
It does practically the same thing.
But don't I still need the

1
2
/*cin >> buf; x = atoi(buf.c_str());
cin >> buf; y = atoi(buf.c_str());*/


to buffer the string?
Topic archived. No new replies allowed.