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. ...
- 03-17-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 6
[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 GuessingGameLast edited by Hawk456; 03-17-2011 at 10:02 PM.
- 03-17-2011 #2
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
- 03-17-2011 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
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!
- 03-17-2011 #4Just 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; }
- 03-17-2011 #5Just 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.
- 03-17-2011 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
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!
- 03-17-2011 #7Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
BTW, instead of a "\n" in c++ code for terminating a line of output, use "<< endl" instead. IE:
instead ofCode:cout << " this is a line of text" << endl;
In the second case, the output is not flushed to the display. Perhaps this is your problem?Code:cout << " this is a line of text\n";
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 03-17-2011 #8Just Joined!
- Join Date
- Mar 2011
- Posts
- 6
I'll try that and see if it works for me.
- 03-17-2011 #9Just 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
.
- 03-17-2011 #10Just 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


Reply With Quote