unix c++

Discussion in 'Programming & Software Development' started by mexicanpete, Aug 23, 2006.

  1. mexicanpete

    mexicanpete Member

    Joined:
    May 30, 2005
    Messages:
    277
    Location:
    townsville queensland
    hi all
    i am doing a subject at uni and i really dint understand how to get the shell working properly. no i have asked around about it but noone is willing to help and the lecture always gives teh same reply and that is google it. now i have been googling it and havent come up with anything that i can get my head around. now we have been using the putty shell thingy that is run on a machine somewhere at the uni and i can logon to that fine but once im in i dont know what the hell im doing and i dont know any codes or anything to access any programs so that i can do any c++ coding.
    we are also using cygwin and cygwin/x now i cant get them to work as in to log me onto the uni system and i dont know what im doing so if anyone can please let me know of any tutorials that might be able to help me i would really apprechiate it

    thanks in advance
    mexicanpete

    if it helps im trying to do all this from my home computer and as yet havent been to the uni to try it
     
  2. chancey

    chancey Member

    Joined:
    Jan 5, 2005
    Messages:
    1,415
    Location:
    Sydney
    You say your using putty, but do you have some gui interface to your uni, because otherwise it would be incredibly slow to try and use the text editor in the shell.

    I don't know what your c++ level of knowledge is, so I will start with the basics. C++ code has to be complied before execution. Open a text editor and put this code into it:

    Code:
    #include <iostream>
    using namespace std;
    int main() {
      cout << "Hello World!" << endl;
      return 0;
    }
    Save it as hw.cpp. Now in the shell you can compile it with the standard GNU compiler:

    Code:
    cd <to wherever you saved the cpp file>
    g++ hw.cpp
    This will compile and generate a file called 'a.out', this is the binary that can be executed with:

    Code:
    ./a.out
    Unix will automatically recognise that its a binary file and will execute it

    Just summing up:
    1. Write the code
    2. Compile it. There are many more options that can be sent to the compiler, but you will pick that up over time
    3. Execute it, with './a.out'
     
  3. OP
    OP
    mexicanpete

    mexicanpete Member

    Joined:
    May 30, 2005
    Messages:
    277
    Location:
    townsville queensland
    thanks for the reply chancey. i do know how to write simple programs like calculator and stuff like that and i know a little bit about switches etc. but the thing that im having trouble coming to grips with is the putty stuff. like i dont know how to bring up an editor in putty and yes it is just a shell. like you can see it as if it were a command prompt or something in windows thats just what it looks like there is no GUI

    thanks for your help though
    i wasnt sure on the compiling stuff but now i know
     
  4. chancey

    chancey Member

    Joined:
    Jan 5, 2005
    Messages:
    1,415
    Location:
    Sydney
    Theres a few text editors like nano. But don't even bother, not worth it.

    1. Download ConTEXT (for writing the code)
    2. Download a free FTP program. That way you can edit the files loacally, then upload them (using the user and pass they gave you), and compile/execute them in the shell
     
  5. BAC :S

    BAC :S Member

    Joined:
    Dec 26, 2001
    Messages:
    1,385
    Location:
    Melbourne
    You can also look into coLinux which lets you run linux natively under windows. I find it good for coding uni work at home (when I don't have linux installed).
     
  6. s3kemo

    s3kemo Member

    Joined:
    May 13, 2003
    Messages:
    5,889
    Location:
    in a house
    I use putty to connect to my uni's unix server aswell. I code inside putty with a text editor called joe. To use it:

    Code:
    cd <to the directory of the file>
    joe file.c
    
    It's a pretty sweet editor.
     
  7. chancey

    chancey Member

    Joined:
    Jan 5, 2005
    Messages:
    1,415
    Location:
    Sydney
    I use fedora core 5 with vmware. It incredibly fast, almost perfect realtime with my intel 3Ghz
     
  8. bugayev

    bugayev Whammy!

    Joined:
    May 15, 2003
    Messages:
    4,093
    Location:
    Melbourne
    chancey, ever heard of vim?

    Medium learning curve, in every relatively recent unix, powerful, extensible, lightweight, and most of all worth a look.

    Depending on the distribution pico/nano may be worth a look too - they are more like your traditional notepad in terms of editing but without the features of vim.
     
  9. OP
    OP
    mexicanpete

    mexicanpete Member

    Joined:
    May 30, 2005
    Messages:
    277
    Location:
    townsville queensland
    ive heard of vim
    we are supposed to be using it but i have not been given any instruction on how to access it
    i think that we have been shown how to access all of the programs in cygwin/x using some graphical programs
    but then again that doesnt help me either
     
  10. BAC :S

    BAC :S Member

    Joined:
    Dec 26, 2001
    Messages:
    1,385
    Location:
    Melbourne
    coLinux doesn't work like a vm. It actually loads the linux kernel under windows, not in a vm. So you can get very close to native linux performance. Running with a little windows xserver like xming is pretty cool.
     
  11. systemdown

    systemdown Member

    Joined:
    Oct 14, 2003
    Messages:
    716
    Location:
    Brisbane 4107
    I use vim ('vi' improved) for coding all the time. It's definitely not an IDE, but it will do syntax highlighting for just about everything which is handy. The learning curve for vi/vim is steep, but being able to edit stuff in any Unix system with just a plain shell prompt is very handy.
    The main thing to remember with vi/vim is that there are two modes - command mode and edit mode - not very intuitive in the beginning, but it becomes easier over time.
    Find a good website that explains the vi/vim basics and you'll be right. To fire it up, while connected in Putty, just type 'vi' - you'll either get classic 'vi' or 'vim' if it has been symlinked that way. To get into edit mode, type 'i' and then anything else you type from that point on will become part of the document text. Hit 'Esc' to get out of edit mode into command mode. While in command mode, type :w <file_name> to save the file, then any subsequent :w will simply save the current state of the file.
    To exit, again while in command mode, type :q or if you're exiting and dont' want to save your file, just add a bang (exclamation point) on the end of that command.
    To edit an existing file / create a new one, from the shell, type vi <file_name>. That should get you started.
     
  12. xsive

    xsive Member

    Joined:
    Jun 29, 2001
    Messages:
    4,343
    systemdown: vi != vim on all systems. Non GNU unixes usually have the original version in which case emacs would be far preferred.

    chancey: I wouldn't bother working on files locally and uploading via ftp. That's very slow and terribly annoying. Unless you're on dialup just work within the shell. I have no problems using shells in realtime in locations as far away as Europe.

    To the OP: It doesn't sound like you've been paying an awful lot of attention during your lectures. This stuff should be covered in lab outlines or similar. Anyway, try your hand at emacs before using vi or perhaps start out with a super basic text editor like pico or jed depending on what is available on your system.

    Google each one and read the manual to find out how to use them. You will also probably need to refer to g++ documentation so you can understand how to use the linker and other lovely wonderful software availble to you. gdb is great if you ever get as far as needing a serious debugger.

    I hope this helps. You really do need to sit down and start from scratch. You're trying to run before you can walk in the unix world.
     
    Last edited: Aug 24, 2006
  13. systemdown

    systemdown Member

    Joined:
    Oct 14, 2003
    Messages:
    716
    Location:
    Brisbane 4107
    Yeah that's why I said when you type 'vi' you'll either get classic vi OR vim if it's been set up that way.. emacs is all well and good, but I think more *nix systems have vi than emacs (in a standard configuration). All personal preference in the end though.

    I can relate to that. My first real *nix experience that lasted more than two days was when I installed NetBSD onto an old box.. figured if all I had was the command prompt, I'd be forced to learn how to use the damn thing. It worked.
     
  14. fr33lanc3r

    fr33lanc3r Member

    Joined:
    Apr 23, 2006
    Messages:
    418
    I o use putty for uni, and have found that the easiest way for me to do coding is by using emacs.
     
  15. phreeky82

    phreeky82 Member

    Joined:
    Dec 10, 2002
    Messages:
    9,710
    Location:
    Qld
    haha just realised you're in townsville, cp1300 i guess? who is the lecturer?

    vi and pico most likely available, pico will be relatively easy to pick up (functions via ctrl key + character as shown at bottom of screen), vi a bit harder but much more capable. you can find instructions on the net of the vi shortcuts and stuff, print them out and keep them with you.

    i personally don't agree with the way they do it: "here, this is unix. this is what you'll be using to program. now, lets learn some new coding concepts using it."

    you end up trying to learn two things at once, using one of them (the one you learn yourself) to learn the other.
     
  16. quirdan

    quirdan Member

    Joined:
    Apr 15, 2002
    Messages:
    1,745
    Location:
    Melbourne
    I'm a sucker for a pretty GUI, so if I'm compiling on remote equipment, I'll use my Windows workstation, and code with UltraEdit32 (excellent software), that supports working from SFTP sites. I'll hit Ctrl+S and by the time I've alt-tabbed back to an SSH session to compile/test it, it's saved and uploaded.

    If I'm testing on a computer on my LAN I'll also use UltraEdit32 but via a SAMBA share.

    I only use vim for editing configuration files. I know a few features and I know it's very powerful but as I said, I'm a sucker for a pretty GUI on a large screen. :)

    Give UltraEdit32 a crack.
     
  17. Logistics

    Logistics Member

    Joined:
    Feb 7, 2003
    Messages:
    1,016
    Location:
    Sydney
    I myself use putty to connect to UNI servers. Basicaly you need to know the unix commands to find your way around.

    Basic commands to find your way around and edit files :)

    I myself use pico to edit files. I do not recommend using VI until you're comfortable with the basic unix commands.

    If you really want to stay away from unix commands you can do what I did the first couple of days. Write a text file in notepad and upload it as binary using CuteFTP to the server. You use the same server name, username and password.

    Though you will need to resave the file in pico or any other text editor to remove the "\r" that windows puts in at the end of each line.

    Hope this helps
     
  18. MadOnion87

    MadOnion87 Member

    Joined:
    Jul 10, 2002
    Messages:
    3,232
    Location:
    Old Trafford, Manchester
    i guess unis all use putty these days yea?
    what i do is i write up the code in my windoze box with an ide like visual studio then i upload it via winscp (a free ftp/scp program)
    as for small changes/hacks that i need to get my code to work i do it through vim
    vim can be quite intimidating as first, still remember the first time i had to use a shell editor was when i was trying to get debian to work
    i had no idea what to use and i remember my comp lecturer typed vi to bring up a text editor and so i did
    didnt know how to even modify the file at first, had to google =D
    now i know the basics of it

    and i think pico is the text editor recommended for newbs in my uni
     

Share This Page

Advertisement: