I don't even know the first thing to do..
How do I "compile" my source code into a program? Can I do it through the C++ program or do I need to download more stuff?
Post has been edited 1 time(s), last time on May 23 2008, 12:31 am by Brontobyte.
None.
No. Your program shouldn't need to do this. Console programs are meant to be executed from the console, and as such, the output should still be on the screen.
There's no such thing as "meant to be executed from the console" except commands. Programs
can be executed on the console. But note that I mainly develop in linux and compiling/running is usually done on the console (except for big projects, but even those!) so what I meant was, any output would still be in the console, even with the program's termination.
I don't even know the first thing to do..
Just do what I said. It's post #70 in this thread.
None.
No. Your program shouldn't need to do this. Console programs are meant to be executed from the console, and as such, the output should still be on the screen.
There's no such thing as "meant to be executed from the console" except commands. Programs
can be executed on the console. But note that I mainly develop in linux and compiling/running is usually done on the console (except for big projects, but even those!) so what I meant was, any output would still be in the console, even with the program's termination.
Exactly. I was correcting the guy who said "put cin.get()" at the end. Guess the quote boxes weren't clear
I don't even know the first thing to do..
Just do what I said. It's post #70 in this thread.
Or follow my instructions in post #75. When you're ready to run your code, press ctrl-F5. or Debug->Start without debugging.
None.
I did that and then what do I do? How do I see a preview of what I just worked on? What do I type to start? I have so many questions...
None.
You didn't do everything we said then. =|
If you're trying Dev-C++ (which is what I highly suggest currently as it gives the cleanest coding experience in Windows), just start a new file and call it "main.cpp".
Copy and paste the code I showed you into the editor, save it and in the toolbars, there should be a "compile" and/or "run" button. Click on that button to run the file.
Due to the fact that windows is weird, insert the code: "cin.get()" right before "return 0", otherwise, the console will automatically close and you won't see anything. To exit the program, just press enter. Note that the program is simply waiting for an input (cin.get()) before it executes "return 0" which closes the program.
For now, just see if you can get that working. And tell us
exactly what you did if you can't get it working.
None.
Do you have a .cpp file in the project? Copy and paste the following into it and then hit ctrl-F5.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
Try getting it to print different things. When you're bored of that, copy and paste this:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout << "Enter your name:" << endl;
cin >> name;
cout << "Hello, " << name << "!" << endl;
return 0;
}
And then from there, start reading:
http://www.cplusplus.com/doc/tutorial/program_structure.html
None.
That said...if your console program is meant to be double-clicked from windows, adding
system("pause");
before the return 0; is the right way to go. But this only works for windows.
Gross.
That's only if you want the ugly "Press any key to exit . . ." or whatever.
TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB -
topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig -
topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!
That said...if your console program is meant to be double-clicked from windows, adding
system("pause");
before the return 0; is the right way to go. But this only works for windows.
Gross.
That's only if you want the ugly "Press any key to exit . . ." or whatever.
It's so much more awesome to use:
while (!kbhit());
remember to include conio.h (though mine has it in stdio.h also).
None.
The "alt + F5" didn't work. I opened my file "Project 1" and then went to the left side tree and clicked on the main.cpp file and then went to the right side and copy and pasted the code you provided, hit alt + F5 and nothing happened.
None.
You want a cin.get(); instead of a return 0; so the program remains open.
This only works once until you hit a key or type something in followed by the enter, then the message comes back up again. Is there some number that I am supposed to input into the "()" area to make it last forever?
<3 YEAH! It worked! Now all that I have to do is learn some code that can actually be used for something decent and BAM! Is there a list somewheres that has every code with what it does? *Starts to Google*
None.
You want a cin.get(); instead of a return 0; so the program remains open.
This only works once until you hit a key or type something in followed by the enter, then the message comes back up again. Is there some number that I am supposed to input into the "()" area to make it last forever?
You don't want it to continue when you hit enter?
<3 YEAH! It worked! Now all that I have to do is learn some code that can actually be used for something decent and BAM! Is there a list somewheres that has every code with what it does? *Starts to Google*
Umm, that would be one HUGE list. Depends on what libraries you are using.
None.
You want a cin.get(); instead of a return 0; so the program remains open.
This only works once until you hit a key or type something in followed by the enter, then the message comes back up again. Is there some number that I am supposed to input into the "()" area to make it last forever?
You don't want it to continue when you hit enter?
<3 YEAH! It worked! Now all that I have to do is learn some code that can actually be used for something decent and BAM! Is there a list somewheres that has every code with what it does? *Starts to Google*
Umm, that would be one HUGE list. Depends on what libraries you are using.
I want it to be able to stay open even after you enter commands, valid or not valid.
I would just want a basic list of code so that I can familiarize myself with it.
None.
I have no idea how to do this.
None.
// While loop example
#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
a = 1;
cout << "Go" "\n";
cin>> c;
cin.ignore();
while (a==1)
if (c==1) {
cout << "Input a number to be cubed." "\n";
cin>> b;
cout << b * b * b "\n";
cin.get();
cout << "Press 1 if you wish to go again" "\n";
cin>> c;
cin.get();
}
else if (c > 1, c < 1) {
return 0;
}
}
A quick program I made to demonstrate.
None.
What is with C and using >> and << as syntax
Also, I assume that while (a==1)
if (c==1) {
cout << "Input a number to be cubed." "\n";
cin>> b;
cout << b * b * b "\n";
cin.get();
cout << "Press 1 if you wish to go again" "\n";
cin>> c;
cin.get();
}
else if (c > 1, c < 1) {
return 0;
}
is equivalent to while (a==1) {
if (c==1) {
cout << "Input a number to be cubed." "\n";
cin>> b;
cout << b * b * b "\n";
cin.get();
cout << "Press 1 if you wish to go again" "\n";
cin>> c;
cin.get();
}
else if (c > 1, c < 1) {
return 0;
}
}
...but I hate lazy syntax.
None.
------ Build started: Project: Calculator, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\admin\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(20) : error C2143: syntax error : missing ';' before 'string'
c:\documents and settings\admin\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(30) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\admin\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(8)' was matched
Build log was saved at "file://c:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\Calculator\Calculator\Debug\BuildLog.htm"
Calculator - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
"There are build errors..."
None.
Line 20
cout << b * b * b "\n";
should be replaced with this:
cout << b * b * b << "\n";
EDIT:
Forgot to include the fix to the other error message.
You need a closing brace "}" for the main() function, which you probably deleted by accident somehow.
Post has been edited 1 time(s), last time on May 25 2008, 6:03 am by Epsilonite.
None.