Help with basic C++ stuff.

Im a beginner is C++, im trying to write a madlib. It doesnt work, but i dont kno why. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
	// variables
	string string1, string2, string3;
	cout << "HELLO, WELCOME TO MAD LIB'S \n";
	cout << "Enter an adjective. \n";
	cin << string1;
	cout << "Now enter a verb. \n";
	cin << string2;
	cout << "Now a name. \n";
	cin << string3;

	return 0;
}
your error messages would be helpful.

basically you have your arrows mucked up a bit when in your IO.

http://www.cplusplus.com/doc/tutorial/basic_io/

cin like this:
cin >>

cout like this:
cout <<

closed account (o3hC5Di1)
Hi there

Just to slightly elaborate on mutexe's answer, the names of these operators helped me to understand the difference and distinguish them:

>> Is called the Extraction operator, for instance: std::cin >> var;. The operator extracts a value from std::cin (standard input) and puts it into "var".

<< Is called the Insertion operator, for instance: std::cout << var;. The operator inserts the value of var into std::cout (standard output), effectively printing it on the screen.

All the best,
NwN
Topic archived. No new replies allowed.