Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 09-19-2007, 07:16 AM   #1
Baseband Member
Join Date: Aug 2006
Posts: 21
Default compiler help?

Hello, I'm trying to compile a small test program I've written to A) see if I remember anything of c++, and B) get used to using gcc to compile. The program has 7 lines of code, which will ask for a name, and return it. here's the program:

#include <iostream>
#include <iostream.h>

//those two are there becasue I don't exactly know which header file I need to use.

main ()
string FirstName="";
string LastName="";
//initialized that way because if I don't do it that way, gcc returns a "FirstName not initialized in this scope" error.

cout<<"What is the first name?";
cout<<"What is the last name?";
cout<<"The name is "<<Firstname<<" "<<Lastname;
return 0;


When I runn gcc with the -c option, it compiles fine. But then, when I take that object file, and try to compile it into a program using the -o option, I get a bunch of "Unreferenced something or other , std::cout" and "cin" errors. Any ideas what could be causing it? And I don't have a ready file with all the errors in it, if anyone could tell me how to send the errors to a file so I can read them later, it would be much appreciated.

demagogue is offline   Reply With Quote
Old 09-20-2007, 07:52 PM   #2
Site Team
celegorm's Avatar
Join Date: Sep 2006
Posts: 10,674
Send a message via AIM to celegorm
Default Re: compiler help?

Ok, first thing first, there is no point in including the same file twice. both of those includes are the same. Some compilers require the .h others do not.

the std errors are probaly related to you not including the standard library. to do this just do

#include<stdlib.h> again, the .h may not be required.

"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 09-21-2007, 04:28 PM   #3
Site Team
David Lindon's Avatar
Join Date: Dec 2002
Posts: 15,233
Default Re: compiler help?

Shouldn't it be int main since you are returning a 0?
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 09-22-2007, 10:56 AM   #4
Fully Optimized
Š88's Avatar
Join Date: May 2005
Posts: 4,775
Send a message via MSN to Š88
Default Re: compiler help?

yes, you must change it to "int main()"
you can remove one of the included iostreams (probably "#include<iostream.h>")
and because you are using strings you need to add "#include <string>" at the top

#include <iostream>
#include <string>

int main()
string FirstName;
string LastName;

cout<<"What is the first name? ";
cout<<"What is the last name? ";
cout<<"The name is "<<Firstname<<" "<<Lastname;
return 0;
Killing under the cloak of war is no different than murder

Kein Alkohol ist auch keine Lösung!
Š88 is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 01:26 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0