Can not compile with VisualStudio

Hi all!

For some reason I can compile this source code with g++ in Cygwin but not with Microsoft Visual Studio 2010 with most recent updates in Windows 7 SP1.

The syntax I use to compile in Visual Studio is..
cl /EHsc new.cpp

In return I get flooded with maybe a few pages of errors.

Anyhow, here is the source code I was working with. This is source code from a book.
I'm trying to learn how to use C++.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
using namespace std;

int main()
{

	// First, let's welcome the user
	cout << "Welcome to the C++ News Network!" << endl << endl;
	
	
	// Then, let's input several values to plug into our headlines.
	// Note that the questions don't always match the names of the
	// variable because we are trying to surprise the player.
	
	string userName;
	cout << "Please type in your first name: " << endl;
	cin  >> userName;
	
	int smallNumber;
	cout << "How many siblings do you have?" << endl;
	cin  >> smallNumber;
	
	float largeNumber;
	cout << "How much money would you like to earn every year?" << endl;
	cin  >> largeNumber;
	
	string colorLeast;
	cout << "Tell us your least favorite color:" << endl;
	cin  >> colorLeast;
	
	string vegObject;
	cout << "Which vegetables have the weirdest shapes?" << endl;
	getline( cin, vegObject );
	
	string deadGuy;
	cout << "Name a famous dead person:" << endl;
	getline( cin, deadGuy );
	
	string celebrityActor;
	cout << "Who is your favorite actor?" << endl;
	getline( cin, celebrityActor );
	
	string politician;
	cout << "Name a current world leader:" << endl;
	getline( cin, politician );
	
	string cartoonCharacter;
	cout << "Who is your favorite cartoon character?" << endl;
	getline( cin, cartoonCharacter );
	
	string weirdGroup;
	cout << "Name a hobby or a profession you find scary: " << endl;
	getline( cin, weirdGroup );
	
	string somethingGross;
	cout << "Name a food item you detested as a child: " << endl;
	getline( cin, somethingGross );
	
	// Finally, let's print out the headlines!
	cout << endl << endl << endl
	     << "And now, today's headlines from the C++ News Wire:"
	     << endl << endl;
	cout << "--------------------------------------------------"
	     << endl;
		  
	cout << "ALIENS SHAPED LIKE " << colorLeast << " " << vegObject
	     << " INVADE THE EARTH, KIDNAPED " << celebrityActor << ", "
	     << "AND RESURRECTED" << deadGuy << "!" << endl << endl;
		  
    cout << userName
	      << " RELEASES NEW ALBUM! " << smallNumber
	      << " COPIES EXPECTED TO BE SOLD!"
	      << endl << endl;
		  
	cout << politician << " CAUGHT IN LOVE TRIANGLE WITH "
	     << cartoonCharacter << " AND SECRET "
	     << weirdGroup << " CULT LEADER!" << endl << endl;
		  
	cout << "WORLDS LARGEST BABY BORN - WEIGHS " << largeNumber
	     << " POUNDS, EATS " << smallNumber << " TONS OF "
	     << somethingGross << " EVERY DAY!" << endl << endl;
		  
	// And we're done!
	return 0;
}


Oh, and by the way. When I execute the program in Cygwin, it skips..

1
2
3
string vegObject;
	cout << "Which vegetables have the weirdest shapes?" << endl;
	getline( cin, vegObject );


And will also skip..

1
2
3
4
string colorLeast;
	cout << "Tell us your least favorite color:" << endl;
	cin  >> colorLeast;
	

...if I decide to use a number such as 70,000 with the comma. But if I use 70000 as my choice instead it will not skip the color part.

Any suggestions?

Add #include <string> to your source.
It compiled!!!

THANKS modoran!!!!

Now it still skips the part where it asks me this..

Which vegetables have the weirdest shapes?

It skips to this part..

Name a famous dead person:

Any more suggestions?
Just a word of advice...

Always start small. Denis Ritchie created C and wrote the famous "Hello, World!" program. It only consists of a few lines and just outputs Hello, World!. But it is enough to determine if your compiler and associated tool chain is working. The way it would have benifited you in the example above is that it would have compiled and ran. At that point you would have known your C++ installation was functional and OK. Then, upon attempting to compile the larger program you would have gotten piles of compilation errors. The diagnostic value of this would have been you would have then known your compiler and installation was OK, but there is something wrong with the program itself. At that point you would read the first one or two error messages to determine what the problem was. This might seem trite but it is a lesson hard acquired by me.
Thanks freddie1 for the advice.

My first program was "hello world!" and it compiled fine with my setup.

I then created other simple programs and they compiled fine too in Windows and Cygwin.

But I know I'm sure that this current program that I'm working with maybe a possible bug is not syntax related.
Is the syntax correct? Because there is a skip in a single part in the program.
Topic archived. No new replies allowed.