Results 1 to 4 of 4

Thread: New to programming, need help compiling first c++...

  1. #1
    Join Date
    Sep 2007
    Beans
    12

    New to programming, need help compiling first c++...

    So I put this into Scite Text Editor

    #include <iostream>
    using namespace std;
    int main()
    {
    int x, y;
    for(x=1;x<=10;x++)
    cout<<count<<endl;
    cin>>y;
    return 0;
    }
    Looks fine to me, and we used this code im my programming class and it worked fine. The problem is, we did this on windows xp using microsoft visual studio or whatever, and I cant figure out how to run this on ubuntu. I used this
    gcc 1st.cpp -o first_c++_Program
    and it seems to have compiled it but my problem is I cant find the binary and I dont know how to run it. Can anyone help out a nooby here? and by the way, this is the first thing ive ever written in any language other than web scripting and BASIC...

  2. #2
    Join Date
    Apr 2007
    Beans
    14,781

    Re: New to programming, need help compiling first c++...

    What do you mean "can't find"? If you type:

    Code:
    ./programName
    It should work.

    If you don't specify -o, it will be named "a.out"

  3. #3
    Join Date
    May 2007
    Location
    Paris, France
    Beans
    927
    Distro
    Kubuntu 7.04 Feisty Fawn

    Re: New to programming, need help compiling first c++...

    0. did you install the "build-essential" package? (sudo apt-get install build-essential)

    1. if you ain't got no output, it worked (which is true for **all** *nix commands I know of, however sometimes you get some output even though it worked)

    2. for C++ use g++ rather than gcc:
    Code:
    $ g++ -o test_output main.cpp more.cpp even_more.cpp
    3. once compiled, run it using:
    Code:
    $ ./test_output
    The ./ part is *very* important (not to say mandatory)


    Don't hesitate to ask if you still have trouble...
    Last edited by aks44; November 6th, 2007 at 10:42 PM.
    Not even tinfoil can save us now...

  4. #4
    Join Date
    Sep 2007
    Beans
    12

    Re: New to programming, need help compiling first c++...

    oh okay, I guess it was because I was using gcc instead of g++, because it just worked, thanks guys!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •