Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
I need some help with the g++ compiler. I've been programming on Windows 7 and I decided to switch to Linux for programming because of the greater number of tools. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2011
    Posts
    6

    Question [SOLVED] G++ Compiler


    I need some help with the g++ compiler. I've been programming on Windows 7 and I decided to switch to Linux for programming because of the greater number of tools. I used a small number guessing game to test g++. But apparently it does not recognize the header files, any of them. Any ideas?

    These are the options I used to compile: g++ -Wall GuessingGame.cpp -o GuessingGame
    Last edited by Hawk456; 03-17-2011 at 11:02 PM.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    we can't really help unless you post the error message if any, we can only guess at what the problem is

    please post us the error message inside of the code tags and source if necessary

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    Posting your test code would also be useful. Please put your code inside code blocks, like this:
    Code:
    // This is some c++ code
    #include <stdlib.h>
    .
    .
    .
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Mar 2011
    Posts
    6
    I've decided to use a different piece of code that I know works in DevC++ in Windows 7. It uses the Windows command line, so should it require any conversion to work in the Linux command line? I'll have to reboot my computer to test it in Linux.

    Dual-booting has it's disadvantages.

    Here's the code:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    void CommandPrompt ();
    void AddCar ();
    void RemoveCar ();
    
    char E;
    
    int a, b, c;
    int Parking [24];
    
    void
    CommandPrompt ()  //The user's starting point.
    {
          cout << "[Car Lot Manager]$ ";
          cin >> E;
          
          switch (E)
          {
                 case 'q' : exit(0);  //Exits program, returning a value of zero.
                 break;
                 case 'a' : AddCar ();  //Enters menu to park a car.
                 break;
                 case 'r' : RemoveCar ();  //Menu for when customer picks up car.
                 break;
                 default : cout << E << "is not a valid command.\n";  //Returns the user's non recognized command plus the text: is not a valid command.
                 CommandPrompt ();  //Runs class CommandPrompt () again.
                 break;
          }
    }
    
    void
    AddCar ()  //Adds a car to the Parking [] array.
    {
           cout << "Enter the number of the car you would like to add: ";  //Corresponds to a parling space number.
           cin >> b;  //Inputs car number into variable b.
           b = b - 1;
           if (Parking [b] == 1) {
                       cout << "There is another car in that spot, car cannot be parked.\n";  //Checks if there is a car in the entered spot.
           }
           else if (Parking [b] == 0) {
                Parking [b] = 1;  //Sets that element of the array to 1.  1 = There is a car in that spot.
           }
           else {
                cout << "Error.  Unknown value.";  //If value is not either 1 or 0, program returns error.
           }
           CommandPrompt ();
    }
    
    void
    RemoveCar ()
    {
           cout << "Enter the number of the car you would like to remove: ";
           cin >> a;
           a = a - 1;
           Parking [a] = 0;  //Sets that element of the array to 0.  0 = There is not a car in that spot.
           CommandPrompt ();
    }
    
    int main(int argc, char *argv[])
    {
        //Text printed only at start up.
        cout << "Car Lot Manager\n";
        cout << "-------------------------------------\n";
        CommandPrompt ();  //Initiates class CommandPrompt ().
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  6. #5
    Just Joined!
    Join Date
    Mar 2011
    Posts
    6
    It seems that there was a problem with the first code i made , because, with the new code i made it compiles fine. But the executable file it made doesn't run.

    Sorry for the number of posts. I can compile working programs in Windows, but apparently not in Linux.

  7. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    Well, it (sort of) works for me. What is your problem with running it?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    BTW, instead of a "\n" in c++ code for terminating a line of output, use "<< endl" instead. IE:
    Code:
    cout << " this is a line of text" << endl;
    instead of
    Code:
    cout << " this is a line of text\n";
    In the second case, the output is not flushed to the display. Perhaps this is your problem?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #8
    Just Joined!
    Join Date
    Mar 2011
    Posts
    6
    I'll try that and see if it works for me.

  10. #9
    Just Joined!
    Join Date
    Mar 2011
    Posts
    6
    I found and installed code::blocks through yum. It compiled and ran properly. I guess I will be using code::blocks until i have g++ working properly. Thanks for all your help.

  11. #10
    Just Joined!
    Join Date
    Mar 2011
    Posts
    15
    I have Fedora 14 and I did

    yum install yumex (under su -)

    then select all and do a search for gcc-c++

    and then apply

    the dependency evaluator should set up everything OK.

    Yumex is very convenient but slow

    eclipse has an plugin for qt that allows GUIs to be generated (like Visual Studio)

    Qt 4.7.1 is a package (like MFC) that compiles and runs just about everywhere

Page 1 of 2 1 2 LastLast

Posting Permissions

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