newbie trying to setup VERY SIMPLE C environment

Need help with C, C++, perl, python, etc?

newbie trying to setup VERY SIMPLE C environment

Postby hertelbrian » 2006-10-05 22:57

ok, let me start this off by saying i'm very new to linux, i'm using debian 2.4.27/-3-386.

im trying to setup an environment that i can compile some very basic C code in. all i want to do right now is read in a file... using the fstream.h
i have downloaded and installed the libc6.dev package...

when i am in the directory my C file lies in and run gcc to compile it.. i get a bunch of errors, first off the bad is that it cant find the fstream.h file.. so i found the path for it.. and put it in my include statement and then the compiler yelled at me for one of the first lines in fstream.h

i'm used to a windows environment and i really am shooting in the dark, all i want to do is compile a very basic C program nothign fancy.. ANY help would be appreciated...

remember
NEWBIE!
thanks in advance
hertelbrian
 
Posts: 13
Joined: 2006-10-05 22:49

Postby ajdlinux » 2006-10-05 23:38

Look at http://www.daniweb.com/techtalkforums/thread11430.html - you will see that you need to include 'fstream', not 'fstream.h'. Also I believe fstream is C++, not C - correct me if I'm wrong.
Jabber: xmpp:ajdlinux@jabber.org.au
Spammers, email this: ajdspambucket@exemail.com.au
ajdlinux
 
Posts: 2480
Joined: 2006-04-23 09:37
Location: Port Macquarie, NSW, Australia

Postby hertelbrian » 2006-10-05 23:52

very well could be C++ but when i tried including as fstream and fstream.h ... when i do fstream it yells at me saying no file exists.. when i do fstream.h compiler yells at me because one of the first lines in fstream.h... it doesnt recognize...
hertelbrian
 
Posts: 13
Joined: 2006-10-05 22:49

Postby ajdlinux » 2006-10-05 23:56

It probably doesn't recognise it because a C compiler can't compile C++ code.
Jabber: xmpp:ajdlinux@jabber.org.au
Spammers, email this: ajdspambucket@exemail.com.au
ajdlinux
 
Posts: 2480
Joined: 2006-04-23 09:37
Location: Port Macquarie, NSW, Australia

Postby beissemj » 2006-10-06 01:21

filestream.h is used in c++, not c. So you need to use g++ to compile it.
Code: Select all
#include <fstream>

int main(void){
  ifstream in("somefile");

    while(!in.eof()) {
          //do something
   }

   in.close();   
}

Code: Select all
$ g++ yourfile.cpp -o executible_name
beissemj
 
Posts: 38
Joined: 2006-07-19 13:53

Postby hertelbrian » 2006-10-06 03:10

beissemj

thanks man... aparently using the correct compiler makes a difference... WHO WOULDA THUNK IT!
hertelbrian
 
Posts: 13
Joined: 2006-10-05 22:49


Return to Programming

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable