Newbie question about coding in C

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Sleven

Newbie question about coding in C

Post by Sleven »

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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29511
Joined: Wed Jul 06, 2011 3:58 am

Re: Newbie question about coding in C

Post by xenopeek »

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: 300
Joined: Sun May 29, 2011 3:26 am
Location: Thailand
Contact:

Re: Newbie question about coding in C

Post by Garvan »

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: DELL Latitude E5520, i5-2520M @ 2.50 GHz, 4GB RAM, Linux Mint 17.2 (2011)
Notebook: DELL Latitude 5280, i5-73000 @ 2.7 GHz., 16 GB RAM, Linux Mint 19.2 (2019)
User avatar
xenopeek
Level 25
Level 25
Posts: 29511
Joined: Wed Jul 06, 2011 3:58 am

Re: Newbie question about coding in C

Post by xenopeek »

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

Re: Newbie question about coding in C

Post by Sleven »

Thanks for the information guys, that explains why it wouldn't compile.
Locked

Return to “Scripts & Bash”