Newbie question about coding in C

Forum rules
Before you post please read how to get help
User avatar
Sleven
Level 4
Level 4
Posts: 400
Joined: Sun Oct 03, 2010 9:03 am
Location: Central Florida

Newbie question about coding in C

Postby Sleven » Tue Sep 20, 2011 7:31 am

Not a bash question, so if there is a more appropriate forum please feel free to move.

I've started working through the, "C for Dummies" book in an attempt to learn C.

I copied some code in which kicks an error out because of a library that's not there.

Code: Select all

#include <iostream>


produces: fatal error: iostream: No such file or directory

I'm using gcc to compile and have a couple questions.

Where are the headers ( stdio.h ) kept, what directory?

How do I go about getting new headers (libraries) i.e. iostream?
LMDE 64 running Cinnamon on an HP Compaq Core2 Duo 4G Ram

User avatar
xenopeek
Level 23
Level 23
Posts: 19229
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Newbie question about coding in C

Postby xenopeek » Tue Sep 20, 2011 8:17 am

I'm rusty on C and C++ (I did 18 years programming on that, but that's ages ago :(). But shouldn't this be:

Code: Select all

#include <iostream.h>

You can see if any file is installed with the following command. For example for stdio.h:

Code: Select all

locate stdio.h
Image

User avatar
Garvan
Level 4
Level 4
Posts: 296
Joined: Sun May 29, 2011 3:26 am
Location: Lao PDR
Contact:

Re: Newbie question about coding in C

Postby Garvan » Tue Sep 20, 2011 9:08 am

Code: Select all

#include <iostream>


Is not C, its C++.

To compile this, save it in a file called test.cc, and use the following command line

Code: Select all

g++ -Wall -c "test.cc"


I think there are other options for the extension of a C++ file, like a big C or cpp.

cpp might be best (as it is also used in windows as far as I know).

Garvan
Notebook: HP 14 Notebook PC 14-r003TX, i5-4210U @ 1.7 GHz, 8GB RAM, Linux Mint 17.2 (Dual boot with Win 10)
Notebook: DELL latitude E5520, i5-2520M @ 2.50 GHz, 4GB RAM, Linux Mint 17.2

User avatar
xenopeek
Level 23
Level 23
Posts: 19229
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Newbie question about coding in C

Postby xenopeek » Tue Sep 20, 2011 9:33 am

Doh :oops: Well, I did C mostly, in my defense :D
Image

User avatar
Sleven
Level 4
Level 4
Posts: 400
Joined: Sun Oct 03, 2010 9:03 am
Location: Central Florida

Re: Newbie question about coding in C

Postby Sleven » Tue Sep 20, 2011 10:42 am

Thanks for the information guys, that explains why it wouldn't compile.
LMDE 64 running Cinnamon on an HP Compaq Core2 Duo 4G Ram


Return to “Scripts & Bash”

Who is online

Users browsing this forum: No registered users and 2 guests