Problem with Visual C++

Hey all,

When I run the following code it works in eclipse and netbeans but not in visual C++. Is there something I'm missing? It keep saying I'm missing parts of code "semi-colons, parenthesis, etc.) but I'm not. Here's the code:

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
// output.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
//include yes/no option.

//Ask name.
string fname, lname, yorn;
cout << "What's your first name?" << endl;
cin >> fname;
cout << "What's your last name? " << endl;
cin >> lname;
cout << "What kind of name is ";
cout << fname << " " << lname << "? HAHA!" << endl << endl;

//Ask if name is liked.

cout << "Do you like your name? (Press Y or N)" << endl;
cin >> yorn;


if (yorn == "y")
     cout << "Seriously? Daaang! I wouldn't!" << endl;
else
     cout << "tough luck! Muahaha!" << endl;

cout << "What's your mother's name?" << endl;
cin >> fname;
cout << fname << "? " << "What kind of name is " << fname << "?" << endl;

}


	system ("PAUSE");
	return 0;
}

Make a new Empty Project without "stdafx.h" and with a real "main" function. Making a "Console Project" will only cause you a multitude of problems.
ok so I still have errors and I created an empty project and added a new .cpp file called main and here's the new code. Is there something wrong still?

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
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	
//include yes/no option.

//Ask name and Taunt.
string fname, lname, yorn;
cout << "What's your first name?" << endl;
cin >> fname;
cout << "What's your last name? " << endl;
cin >> lname;
cout << "What kind of name is ";
cout << fname << " " << lname << "? HAHA!" << endl << endl;

//Ask if name is liked.

cout << "Do you like your name? (Press Y or N)" << endl;
cin >> yorn;


if (yorn == "y")
     cout << "Seriously? Daaang! I wouldn't!" << endl;
else
     cout << "tough luck! Muahaha!" << endl;

cout << "What's your mother's name?" << endl;
cin >> fname;
cout << fname << "? " << "What kind of name is " << fname << "?" << endl;

}


	system ("PAUSE");
	return 0;
}
Yes, there's a brace on line 35 that shouldn't be there.
still nothing :( this appears on the output window:

c:\program files\microsoft visual studio 10.0\vc\include\ostream(487): or 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> while trying to match the argument list '(std::ostream, std::string)'
That's only the bottom of the error. Try copying and pasting the entire build output...
ok. Here's the pastebin. It's a pretty long error:

http://pastebin.com/ciVESW6e
Also. When I run a simple hello world:

#include <iostream>

using namespace std;

int main(){

cout << "Hello, World!" << endl;

system("PAUSE");
return 0;

}

I get the following errors. Although the prompt does come up and it works:

'plz.exe': Loaded 'C:\Documents and Settings\Steven\My Documents\Visual Studio 2010\Projects\plz\Debug\plz.exe', Symbols loaded.
'plz.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
'plz.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
'plz.exe': Loaded 'C:\WINDOWS\system32\msvcp100d.dll', Symbols loaded.
'plz.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded.
'plz.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll', Cannot find or open the PDB file
'plz.exe': Loaded 'C:\WINDOWS\system32\version.dll', Cannot find or open the PDB file
'plz.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Cannot find or open the PDB file
'plz.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Cannot find or open the PDB file
'plz.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Cannot find or open the PDB file
The program '[4104] plz.exe: Native' has exited with code 0 (0x0).
Those aren't errors, only warnings. Those appear if you didn't build your exe with debug information. You can ignore them, unless of course you want to debug/step through your code.

In terms of the errors, it looks like you simply forgot to #include <string> in your code.
hmm... I'm still getting the same errors :S even with the <string>.
also.. Maybe it was something i didn't do when i installed VS. I have dual boot with mac and windows and I had to install mingw so maybe that's the problem? Does everyone usually have to go through all this too? I know in mac I didn't have to install anything else with eclipse or netbeans.. just ran the program and everything started fine.
Well.. I'm not sure what happened.. but I made a similar program from scratch and there were no errors. Is there a difference that could've made errors?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string name,choice;

	cout << "Enter your name and press ENTER" << endl;
	cin >> name;
	cout << "Your name is " << name << "? (ENTER Yes or No)" << endl;
	cin >> choice;

	if (choice == "y"||"Y"||"Yes"||"yes")
		cout << "Really? You really need a name change!" << endl;
	else
		cout << "Good! I was worried for a second there!" << endl;

	system("pause");
	return 0;

}
another thing. The "if" section is a bit off. I'm trying to write that if either y, Y, Yes, or yes is entered then it outputs the following statement.. but it seems like even if you put a random letter it outputs the first statement. is the "||" the right syntax for that?
if (choice == "y"||"Y"||"Yes"||"yes")
should be
if(choice == "y" || choice == "Y" || choice == "Yes" || choice == "yes")
Is there a difference that could've made errors?

In your other program, you #include <fstream> . If you include fstream do the errors return?
Topic archived. No new replies allowed.