LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-16-2004, 08:28 AM   #1
Israfel2000
Member
 
Registered: May 2004
Location: Underground base in the mountains
Distribution: FreeBSD, Fedora, Ubuntu
Posts: 87
Blog Entries: 2

Rep: Reputation: 18
A simple program on C++ for the linux with an error.


I am starting to learn how to use the gcc on Red Hat Linux. I'm using the Emacs text editor for making C++ Programs. This is a sample of one of the simple programs I have:

#include <iostream.h>
int main()
{
int Val, Amt, Tot, Cnt;
Amt=30;
Tot=12;
Cnt=46;

//Compute Val = rightmost expression
Val=(Amt++, --Tot, Cnt+3);

//Display the result
std::cout<<Val;

return 0;
}

After I compile it it gives me this error:

./values.cpp: Line 2: syntax error near unexpected token `('
./values.cpp: Line 2: `int main()'

I don't understand why I get this error. I would greatly appreciate your help. Thanks in advance.
 
Old 06-16-2004, 09:44 AM   #2
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 17
try putting this line after the include statement

using namespace std;

and then try compiling the code
 
Old 06-16-2004, 10:00 AM   #3
Israfel2000
Member
 
Registered: May 2004
Location: Underground base in the mountains
Distribution: FreeBSD, Fedora, Ubuntu
Posts: 87
Blog Entries: 2

Original Poster
Rep: Reputation: 18
I put in what you told me to put in but i get this error:

./values.cpp: Line 2: using: command not found
./values.cpp: Line 3: syntax error near unexpected token `('
./values.cpp: Line 3: `int main()'

 
Old 06-16-2004, 11:40 AM   #4
Majjj
LQ Newbie
 
Registered: Sep 2003
Location: Hyderabad
Distribution: Fedora Core 2
Posts: 10

Rep: Reputation: 0
Hi there

u seem to be trying to execute the cpp file .
You can only run an executable.
The compiler compiles the code and puts the output in a.out file.

for ex.
do
g++ values.cpp
it will make a file named a.out
execute it using
./a.out

This will work and try google for some elementry tutorials on how to
compile and execute a c/c++ program in linux.
Majjj
 
Old 06-16-2004, 06:25 PM   #5
Israfel2000
Member
 
Registered: May 2004
Location: Underground base in the mountains
Distribution: FreeBSD, Fedora, Ubuntu
Posts: 87
Blog Entries: 2

Original Poster
Rep: Reputation: 18
Thanks for your help guys. It worked. The program had a few errors that I had to work out but finally it worked. I will look up in google for those tutorials. Thanks again.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple C program - error with float J_K9 Programming 2 10-24-2005 11:36 AM
simple mail program works on windows and not on linux naijaguy Linux - General 1 04-21-2005 08:45 PM
Simple C pow() program, strange error funkymunky Programming 2 06-25-2004 04:20 AM
Error for a very simple C program pkashyap Linux - Newbie 2 03-11-2004 10:24 AM
::Simple Linux Program:: XxAndyxX Linux - General 15 06-15-2003 06:08 AM


All times are GMT -5. The time now is 02:47 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration