Newbie question about coding in C

Forum rules
Before you post please read this

Newbie question about coding in C

Postby Sleven on 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
Sleven
Level 4
Level 4
 
Posts: 405
Joined: Sun Oct 03, 2010 9:03 am
Location: Central Florida

Linux Mint is funded by ads and donations.
 

Re: Newbie question about coding in C

Postby xenopeek on 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
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14561
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Newbie question about coding in C

Postby Garvan on 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
Desktop: Dell, Intel Core 2 Duo E7500 @ 2.93Ghz, 2GiB RAM, Linux Mint 13 Maya.
Net-book: SAMSUNG N148-Plus, 2x Intel Atom CPU N450 @1.66Ghz, 1GB RAM, lubuntu 12.04.
User avatar
Garvan
Level 4
Level 4
 
Posts: 273
Joined: Sun May 29, 2011 3:26 am
Location: Cambodia

Re: Newbie question about coding in C

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

Doh :oops: Well, I did C mostly, in my defense :D
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14561
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Newbie question about coding in C

Postby Sleven on 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
User avatar
Sleven
Level 4
Level 4
 
Posts: 405
Joined: Sun Oct 03, 2010 9:03 am
Location: Central Florida


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest