473,796 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing, testing/compiling, and running C++ in linux (Ubuntu)

I am taking a C++ class and would like to use a Linux based IDE vs C+
+ .Net but I am a little lost in how to go about this. I think that
the IDE and compilation tools are separate under Linux. I have tried
to take code written and tested under C++ .Net and tried compiling it
in Linux via gcc but I keep getting errors.

The code:
#include <iostream>

using namespace std;

int main()
{
//declare variables
double score1, score2, score3, average;

//enter inputs
cout << "Enter score for first test: ";
cin >score1;
cout << "Enter score for second test: ";
cin >score2;
cout << "Enter score for third test: ";
cin >score3;

//display outputs
if (score1 >= 0 && score2 >= 0 && score3 >= 0)
{
average = (score1 + score2 + score3) / 3;
cout << "The average for the three test is: "
<< average << "\n";
}
else
cout << "You must enter a score for each test"
<< "equal to or greater than zero." << "\n";

return 0;
} //end of main function

The errors:

user@user1:~$ gcc -o /home/user/test.out /home/user/testing.c
/home/user/testing.c:1:20: error: iostream: No such file or directory
/home/user/testing.c:3: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'namespace'
/home/user/testing.c: In function 'main':
/home/user/testing.c:11: error: 'cout' undeclared (first use in this
function)
/home/user/testing.c:11: error: (Each undeclared identifier is
reported only once
/home/user/testing.c:11: error: for each function it appears in.)
/home/user/testing.c:12: error: 'cin' undeclared (first use in this
function)

Any help on how I can accomplish my assignments in Linux vs Windows
would be appreciated. I am having to use VMWare now in order to use
the C++ >Net IDE.

James

Jan 30 '07 #1
6 10797
Cybex wrote:
I am taking a C++ class and would like to use a Linux based IDE vs C+
+ .Net but I am a little lost in how to go about this. I think that
the IDE and compilation tools are separate under Linux. I have tried
to take code written and tested under C++ .Net and tried compiling it
in Linux via gcc but I keep getting errors.

The code:
#include <iostream>

using namespace std;

int main()
{
//declare variables
double score1, score2, score3, average;

//enter inputs
cout << "Enter score for first test: ";
cin >score1;
cout << "Enter score for second test: ";
cin >score2;
cout << "Enter score for third test: ";
cin >score3;

//display outputs
if (score1 >= 0 && score2 >= 0 && score3 >= 0)
{
average = (score1 + score2 + score3) / 3;
cout << "The average for the three test is: "
<< average << "\n";
}
else
cout << "You must enter a score for each test"
<< "equal to or greater than zero." << "\n";

return 0;
} //end of main function

The errors:

user@user1:~$ gcc -o /home/user/test.out /home/user/testing.c
/home/user/testing.c:1:20: error: iostream: No such file or directory
/home/user/testing.c:3: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'namespace'
/home/user/testing.c: In function 'main':
/home/user/testing.c:11: error: 'cout' undeclared (first use in this
function)
/home/user/testing.c:11: error: (Each undeclared identifier is
reported only once
/home/user/testing.c:11: error: for each function it appears in.)
/home/user/testing.c:12: error: 'cin' undeclared (first use in this
function)
not sure but looks like the compiler was compiling C code not C++
(mistakenly.) Why not try g++ instead of gcc.
>
Any help on how I can accomplish my assignments in Linux vs Windows
would be appreciated. I am having to use VMWare now in order to use
the C++ >Net IDE.
For a standard ISO C++ program any tool would be fine.
>
James
Ben
Jan 30 '07 #2
That worked like a charm! Thanks

gcc was the only tool I found reference to in a Linux for programmers
book that talked about C/C++. So doing things this way should work
right? Is C++ the same across the two platforms? This is an intro to
C++ so I doubt we will get very far beyond the basics.

James

Jan 30 '07 #3
Cybex wrote:
That worked like a charm! Thanks

gcc was the only tool I found reference to in a Linux for programmers
book that talked about C/C++. So doing things this way should work
right? Is C++ the same across the two platforms? This is an intro to
C++ so I doubt we will get very far beyond the basics.

James
The "GCC" Collection includes the "gcc" compiler for C and
the "g++" compiler for C++. Always compile -and- link
C++ programs using "g++".
Jan 30 '07 #4
Cybex wrote:
That worked like a charm! Thanks

gcc was the only tool I found reference to in a Linux for programmers
book that talked about C/C++. So doing things this way should work
right? Is C++ the same across the two platforms? This is an intro to
C++ so I doubt we will get very far beyond the basics.

James
The newsgroup for the GCC 'C' compiler is

gnu.gcc.help

The newsgroup for the GCC 'C++' compiler is

gnu.g++.help
Jan 30 '07 #5
On 1ÔÂ30ÈÕ, ÉÏÎç11ʱ29·Ö, Larry Smith <lsm...@nospam. comwrote:
Cybex wrote:
That worked like a charm! Thanks
gcc was the only tool I found reference to in a Linux for programmers
book that talked about C/C++. So doing things this way should work
right? Is C++ the same across the two platforms? This is an intro to
C++ so I doubt we will get very far beyond the basics.
James

The newsgroup for the GCC 'C' compiler is

gnu.gcc.help

The newsgroup for the GCC 'C++' compiler is

gnu.g++.help
Be sure your GCC installation is correct, also , change your file name
test.c to test.cpp

Jan 30 '07 #6
Cybex wrote:
I am taking a C++ class and would like to use a Linux based IDE vs C+
+ .Net but I am a little lost in how to go about this. I think that
the IDE and compilation tools are separate under Linux. I have tried
to take code written and tested under C++ .Net and tried compiling it
in Linux via gcc but I keep getting errors.

The code:
#include <iostream>

using namespace std;

int main()
{
//declare variables
double score1, score2, score3, average;

//enter inputs
cout << "Enter score for first test: ";
cin >score1;
cout << "Enter score for second test: ";
cin >score2;
cout << "Enter score for third test: ";
cin >score3;

//display outputs
if (score1 >= 0 && score2 >= 0 && score3 >= 0)
{
average = (score1 + score2 + score3) / 3;
cout << "The average for the three test is: "
<< average << "\n";
}
else
cout << "You must enter a score for each test"
<< "equal to or greater than zero." << "\n";

return 0;
} //end of main function

The errors:

user@user1:~$ gcc -o /home/user/test.out /home/user/testing.c
/home/user/testing.c:1:20: error: iostream: No such file or directory
/home/user/testing.c:3: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'namespace'
/home/user/testing.c: In function 'main':
/home/user/testing.c:11: error: 'cout' undeclared (first use in this
function)
/home/user/testing.c:11: error: (Each undeclared identifier is
reported only once
/home/user/testing.c:11: error: for each function it appears in.)
/home/user/testing.c:12: error: 'cin' undeclared (first use in this
function)

Any help on how I can accomplish my assignments in Linux vs Windows
would be appreciated. I am having to use VMWare now in order to use
the C++ >Net IDE.
Rename to testing.cpp, compile with g++. Otherwise you risk
the compiler thinking it's C, not C++.

HTH,
- J.
Jan 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2482
by: Martin Maney | last post by:
Apologies if this isn't news here - I've been too busy this last week or so for even skimming the traffic here, in part because I've been messing around with Ubuntu's preview release on a spare machine... and, of course, spending time on their very busy mailing list. :-) I didn't find any mention of Ubuntu in a quick scan of recent messages, so... Ubuntu is a Linux distribution that starts with the breadth of Debian and adds regular...
0
1253
by: Billy Patton | last post by:
I have to have my code done for 32 and 64 bit machines on both Linux and Solaris. Compiling, not a problem. Testing 32 is not a problem. But I get segmentation faults when I test on 64 bit machines. Here's where my problem comes in. I have this macro: static char thr_buf; #define THROW(msg) { sprintf(thr_buf,"(%s,%s,%d) : %s",__FILE__,__FUNCTION__,__LINE__,msg); throw(thr_buf); }
4
1754
by: John Salerno | last post by:
I'm interested in trying out Linux, probably Ubuntu, but I was wondering which distribution you guys like to use (because it's a pain trying to decide!) and you guys are smart. And to keep it Python related, I'll also ask, is there anything special I need to know about using Python on Linux? Do any things change, or can it be used just as I use it on Windows? Thanks!
5
1588
by: Py PY | last post by:
(Apologies if this appears twice. I posted it yesterday and it was held due to a 'suspicious header') I'm having a hard time trying to get a couple of tests to pass when compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's not too far removed from the desktop edition but, clearly, I need to tweak something or install some missling libs. uname -a
19
1676
by: Vincent Delporte | last post by:
Hello I'm thinking of using Python to build the prototype for a business web appplication. The development and test machine is XP, while ultimate deployment will be on a shared Unix web host. What would you recommend I get, besides the Python engine itself? Good IDE (Kodomo?) ? Some kind of GUI designer? Add-on's? Other tools? Thank you.
18
2402
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not that great. One of the cons of ASP & Javascript is that they're both interpreted, which means one has twice the amount of work to do interms of syntax checking & semantic/runtime checking. Another bad thing is that ASP & Javascript doesn't have...
60
4115
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
On May 3, 8:09 am, apati...@gmail.com wrote: A programmer that uses Vista? :O Vista is a hog of an operating system. Downgrade to Windows XP or get yourself a Linux distro.
2
2171
by: Jakes | last post by:
Hey guys. Hope this is the right forum for this kind of question... I'm doing some vacation work and I have been given c++ code that has been written in Microsoft visual studio and I need to evaluate the code and report back on which source files the code isn't compatible with the Linux platform. I want to test each source/header file on it's own for any erroneous code. For example open the ex.cpp and ex.h files and test if the code is Linux...
8
5958
by: defn noob | last post by:
How hard is it to write a driver for a wireless network card (Ubuntu doesn't support my card)? I have a lot of programming experience but in high-level languages like Python and just minimal C knowledge. How big is the project, hard to say perhaps but could anyone guess how many lines approximately? Is it technically hard or just a lot of specifications to meet?
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.