Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: Siplus on 29 March 2003, 21:17

Title: c++/gcc or whatever in linux
Post by: Siplus on 29 March 2003, 21:17
reading "C Programing in Linux" reminded me of a few questions...

in my programming class, (we use Visual Studio 6...), my teachers tells us to use
system("CLS"); to clear the screen. will this command work in linux?

also, i haven't been able to program anything in linux. i don't really know how to use gcc, or what to write a program in

i tried to write a simple c++ program that would just print "Hi" to the screen, but i didn't know how to compile/build it. i wrote it in pico.
i tried ./program, gcc program... but these didn't work. how do you get a c++ program to compile/build/run?
Title: c++/gcc or whatever in linux
Post by: slave on 29 March 2003, 22:17
We're real cool in my programming class, we have sun workstations and are forced to use gcc.  Haha!


To compile a program in gcc (a simple one) type this:

gcc hello.c

that's it.  It wil generate a file called a.out, type

./a.out

to run it.

To clear the screen in Linux, use the command

clear();

This works for ncurses only, which is kinda like conio.h in dos.
Title: c++/gcc or whatever in linux
Post by: Siplus on 29 March 2003, 22:24
aww...i wish i was forced to use a unix os!!   :(

i guess i couldn't compile b/c i didn't put a '.c' after. why do you need to do this? i thought file extentions weren't needed in linux

never heard of ncurses or  conio.h...in fact, these are the only header files i know of:
iostream.h
stdlib.h
string.h
iomanip.h
math.h
fstream.h
so as you can see, i don't really know much c++... in my school we have 3 years of programming, 2 of which are QB. i managed to let them in the c++ year w/o wasting my time with QBasic, although it was a little rough expanding my mind to a programming langauge like c++ (my first and only langauge)

i think clear(); is a lot simpliar then system("CLS");, are there many shorter versions of commands/functions in the linux header files?
Title: c++/gcc or whatever in linux
Post by: slave on 29 March 2003, 22:27
Well you see, c and c++ files look very similar so you have to specify with an extension.  This is one of the only cases in Linux where the extension matters.
Title: c++/gcc or whatever in linux
Post by: jtpenrod on 7 April 2003, 10:14
quote:
i guess i couldn't compile b/c i didn't put a '.c' after. why do you need to do this? i thought file extentions weren't needed in linux
File extensions are meaningless to Linux itself. However, gcc is an application that Linux runs. And for some applications, file extensions do matter. However, it is possible to override file extensions in gcc, so you can use other extensions if you'd like to do that. The way to compile something with gcc would be to enter:
Code: [Select]
That will compile a simple, one file, program, add debug symbols, turn on all warnings, and make an executable called "hello" (Linux executables seldom have extensions such as *.exe, although you can add them if desired.)
quote:
never heard of ncurses
NCurses is a basic graphical output. It preceeded X, and is used for applications such as Vi and EMACS without X support. NCurses doesn't allow for anything really fancy beyond drawing text on the screen.
_______________________________________
Live Free or Die: Linux
(http://www.otakupc.com/etsig/dolphin.gif)
Their fundamental design flaws are completely concealed by their superficial design flaws.