Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 17th, 2008, 02:23 AM
Registered User
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Errors Compiling

I am having errors compiling a simple Hello World with g++ in linux.

The program source is written like this

1: #include <iostream.h>
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }

When I compile I get this error:

geoff@Geoffs-Ubuntu-X64:g++ Hello-World.cpp
Hello-World.cpp:1: error: stray ‘#’ in program
Hello-World.cpp:1: error: expected unqualified-id before numeric constant


I wrote the program exactly as told.




Reply With Quote
  #2 (permalink)  
Old June 17th, 2008, 02:57 AM
Registered User
 
Join Date: Jun 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I got the first exercise to work by removing the numbers. Now I got another problem compiling this source.

Source Code:

#include <iostream.h>
int main()
{
int x = 5;
int y = 7;
cout "\n";
cout << x + y << " " << x * y;
cout "\n";
return }

Error:

geoff@Geoffs-Ubuntu-X64:~/Documents/Learn-C++/Source/Learn-C++-in-21-Days$ g++ -Wno-deprecated Guess.cpp
Guess.cpp: In function ‘int main()’:
Guess.cpp:6: error: expected `;' before string constant
Guess.cpp:8: error: expected `;' before string constant

I have no idea what the program is supposed to do. The idea of the exercise is to take a guess at it.
Reply With Quote
  #3 (permalink)  
Old July 3rd, 2008, 07:05 AM
Registered User
 
Join Date: Jul 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try
cout << "\n";
or
cout << endl;
instad of
cout "\n";

when using cout always use the << operator when adding elements to the stream.


Reply With Quote
  #4 (permalink)  
Old July 21st, 2008, 04:48 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default


 #include <iostream.h>
 int main()
 {
 int x = 5;
 int y = 7;
 cout "\n";
 cout << x + y << " " << x * y;
 cout "\n";

 return 0; // forgot the 0;
 }


Reply With Quote
  #5 (permalink)  
Old July 22nd, 2008, 12:33 PM
Authorized User
 
Join Date: Jan 2008
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 #include <iostream.h> do not use .h with standart libraries . <iostream> is just fine.


Reply With Quote
  #6 (permalink)  
Old October 16th, 2008, 01:27 AM
Authorized User
 
Join Date: Oct 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am got a little problem while compiling a program including the my c++ features. The code is meant to connect to a my c++ server and grab some data. I am sure the codding is correct then what can i do?
==========================================
Victor
Our mission is to provide high quality end to end solutions to the BPO segment in a manner that will improve the operational efficiency while reducing the cost of the services to the client.
[email protected]


Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors when Compiling a Class File Jim3 General .NET 1 March 16th, 2005 01:57 AM
errors compiling on beta2 gaid BOOK: ASP.NET Website Programming Problem-Design-Solution 3 February 21st, 2005 12:25 AM
Can't get errors to display with <html:errors> michaeldill JSP Basics 0 August 2nd, 2004 01:47 PM
Errors Errors DB Errors Ljhopkins VS.NET 2002/2003 0 July 15th, 2003 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.