View Full Version : New to C++, and need halp!
Ok, I have made a sample .cpp file...and here is the code. Im using Notepad++
code:
/*
This is a simple C++ program.
Call this file Sample.cpp.
*/
#include <iostream>
using namespace std;
// A C++ program begins at main().
int main()
{
cout << "C++ is power programming.";
return 0;
}
This is where i run into problems, how can I compile it? My original though was using the Visual C++ compiler code, which is something liek this:
C:\...>cl -GX Sample.cpp
coares that wouldn't make sense, as i dont have visual C++, i only HAVE notepad++. I need a way to compile my .cpp file, any suggestions? or could i make a simple compiler myself? If i got the code, and the compiler was a .exe or something, that compiled .cpp to .exe or something, I could do it, coares i'd need to know how to do that first.
ANYWAYS, so i need help compiling my .cpp file.
_r.u.s.s.
15-11-2008, 12:08 AM
http://www.google.com/search?hl=en&safe=off&q=compile+c%2B%2B+windows+free&btnG=Search
AlumiuN
15-11-2008, 08:05 AM
Here's the one I use: DevC++ 4.9.9.2 (Beta 5) (http://www.bloodshed.net/devcpp.html)
To compile your sample code, just load it in Dev and hit the compile button. :)
using DevC++, i put the .cpp file in, and said compile, and it said it did, but to where did it compile? And when i clicked "run", the command prompt would open for like 1/8th of a second then close. Hm :(
ANYWAYs, while i figure this out, ima also make more codes.
_r.u.s.s.
15-11-2008, 09:51 PM
fubb, if you don't know what are you doing, don't do it
well no my pc just down't agree with the Comand Prompt whatsoever. Maybe if they were .bats...
dosraider
15-11-2008, 10:22 PM
fubb, if you don't know what are you doing, don't do it
Story of my life, never know what I'm doing, but I do it anyway.
:bleh:
AlumiuN
15-11-2008, 11:47 PM
using DevC++, i put the .cpp file in, and said compile, and it said it did, but to where did it compile? And when i clicked "run", the command prompt would open for like 1/8th of a second then close. Hm :(
ANYWAYs, while i figure this out, ima also make more codes.
Probably because it prints it then quits. Put a system("pause"); before return 0; and you will also need to add #include <stdlib.h> below #include <iostream> (well, I think stdlib.h is the right one...)
_r.u.s.s.
16-11-2008, 06:06 AM
sorry i was quite sh*tfaced yesterday when i wrote that. do it, you won't lose anything from trying :D
why won't you search for the program name, to see where it has been compiled? (i never worked in devc++) then you will be able to run the program via running cmd, so it doesn't close automatically
i think there were also options about this closing cmd after program in windows
AlumiuN
17-11-2008, 06:44 AM
I think it just compiles it to the memory and runs it from there. You need to build it to create an EXE.
using DevC++, i put the .cpp file in, and said compile, and it said it did, but to where did it compile? And when i clicked "run", the command prompt would open for like 1/8th of a second then close. Hm :(
ANYWAYs, while i figure this out, ima also make more codes.
You need a wait command like system("pause");
AlumiuN
29-11-2008, 07:55 AM
You need a wait command like system("pause");
Exactly what I said just after he had that problem. :doh:
Exactly what I said just after he had that problem. :doh:
oh sorry i've seen it too late
gamers2k
19-12-2008, 02:26 PM
Quick thought, why not get yourself visual studio - might save you time setting up your compiler and all.
The Bard
21-12-2008, 05:23 PM
I think that #include<cstdlib> is better for C++ if you're using system() order.
Or you can do the old trick with
char z;
cin >> z;
on the end of the program, you can probably guess how that one works...
AlumiuN
21-12-2008, 09:51 PM
Or you can do the old trick with
char z;
cin >> z;
on the end of the program, you can probably guess how that one works...
Very cunning... although, if you really want to, you could add:
cout << "Press enter to continue..."
you can also use the getch() function
#include <conio.h>
int main()
{
...
cout<<"press any key";
getch();
return 0;
}
devilisme
15-04-2009, 05:31 PM
you can also use
...
cin.get();
return 0;
}
that did the work for me..
Acero
30-11-2009, 01:28 AM
I would second this, pick up Visual C++ Express Edition and make your life easier.
Nothing wrong with DevC++ either but Visual Studio contains many small helpers to assist a person just learning.
Good luck with your learning and stick with it! :thumbs:
Also, C++ is a great language but I think C# might be a bit easier when you are just learning to program. So many of the more taxing problems are abstracted away letting you focus on the learning and not the clean up and memory handling details.
Quick thought, why not get yourself visual studio - might save you time setting up your compiler and all.
_r.u.s.s.
30-11-2009, 04:59 PM
if you're going for the commercial c++ compilers, borland c++ builder (http://en.wikipedia.org/wiki/C%2B%2BBuilder) is one of the best tools available out there
edit: i see that some `embarcadero technologies` bought it, i hope they don't screw it up like adobe with flash
nikakd
16-08-2010, 02:32 PM
You should use Code::Blocks, it's the best and it's free. I also believe (but i'm not sure) that it pauses at the end of the program so you can see the output.
If not, you should use a getch or cin<<z as the other guys said
vBulletin® v3.7.1, Copyright ©2000-2025, Jelsoft Enterprises Ltd.