|
Page 2 of 2 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73196
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Fri, 16th Dec 2011 15:31 Post subject: |
|
 |
You create a new, empty project, add a CPP source file and type that in. Then build it, and CTRL+F5 to run.
|
|
Back to top |
|
 |
b0se
Banned
Posts: 5901
Location: Rapture
|
Posted: Fri, 16th Dec 2011 15:34 Post subject: |
|
 |
iNatan wrote: | You create a new, empty project, add a CPP source file and type that in. Then build it, and CTRL+F5 to run. |
That's the problem, ctrl+f5 or debug, it's not working .
The faded out .
[spoiler][quote="SteamDRM"]i've bought mohw :derp: / FPS of the year! [/quote]
[quote="SteamDRM"][quote="b0se"]BLACK OPS GOTY[/quote]
No.[/quote][/spoiler]
|
|
Back to top |
|
 |
|
Posted: Fri, 16th Dec 2011 15:52 Post subject: |
|
 |
b0se wrote: | What I dont understand is how the fuck I compile this in VC2010 :
Listing 1.1. HELLO.CPP, the Hello World program.
1: #include <iostream.h>
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }
What I mean is that out of what I wrote should come : Hello World! , how do I do that ? | Okay first problem are the numbers on the left, they are not part of the program they are just for reference so the author can say "okay on line 2 this shit happened, now on line 5 some other shit happened because of line 4".
If you don't want to type this yourself and are just copy-pasting, and you should be typing these short programs and copying the long ones later, after you copy this into VS place cursor on the beginning, here it's #, HOLD ALT and select everything but the numbers on the left and copy that, then select everything and paste that, you should get the code without the numbers.
|
|
Back to top |
|
 |
|
Posted: Fri, 16th Dec 2011 16:41 Post subject: |
|
 |
also when you compile that program it will just flash briefly and exit immediately (that's what it's supposed to do).
If you want the window to stay open you can add another line with "cin.get();" just before "return 0;". This will tell the program to wait for user to input some character, which will force the window to stay open until you enter something.
|
|
Back to top |
|
 |
|
Posted: Fri, 16th Dec 2011 16:50 Post subject: |
|
 |
Yes, you screen will flash if you just press F5 but with CTRL+F5 it will stay up.
|
|
Back to top |
|
 |
|
Posted: Fri, 16th Dec 2011 16:58 Post subject: |
|
 |
Actually that won't happen if he has created "Empty project" as iNatan described. If he created Win32 console application it will.
Also the code has more errors. It should be "#include <iostream>", instead of "#include <iostream.h>". And you need to add "using namespace std;" on a line right after that.
You seem to be using an out of date tutorial bose.
|
|
Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 73196
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Fri, 16th Dec 2011 17:08 Post subject: |
|
 |
Actually with
#include <iostream.h>
You don't need the using namespace declaration.
Also, isn't Win32 console application the default project type in VC?
|
|
Back to top |
|
 |
|
Posted: Fri, 16th Dec 2011 17:08 Post subject: |
|
 |
Just remove all the .h and it will work.
|
|
Back to top |
|
 |
|
Posted: Mon, 19th Dec 2011 12:56 Post subject: |
|
 |
iNatan wrote: | Actually with
#include <iostream.h>
You don't need the using namespace declaration.
Also, isn't Win32 console application the default project type in VC? |
Yeah but iostream.h doesn't come with Visual Studio 2010. (I don't have VC++ 2010 but I assume it doesn't come with that one either since it's been deprecated long time ago).
It is the first selected project type, but there is also the "Empty project" project type. And while the default subsytem for an empty project used to be console in previous visual studio versions, since 2010 the default subsystem is not defined for an empty project, which is the cause of the issue I mentioned.
|
|
Back to top |
|
 |
linnx88
Posts: 230
Location: dutch coffee shop
|
Posted: Thu, 9th Feb 2012 16:16 Post subject: |
|
 |
Take it from a programmer. C++ is THE language to learn, iNatan is correct!
If you're just starting out, you can start with C and then continue on to C++, which is an extended version of C with object orientation and a bunch of other features.
C++ lets you program at low level (bit manipulation, fitting in several data types in 1 address via unions, memory management, etc) and is THE language to learn if you're interested in heavy duty programming, game programming or game hacks programming.
For everything else, you can try C#, which has a C/C++ like syntax but without the memory management complications. But these so called "complications" like managing dynamically allocated memory via copy constructors and having the ability to free memory EXACTLY when you, the programmer want, is what makes C++ so powerful.
C++ is unlikely to be beaten by any other language out there.
I don't recommend learning C++ from any web sites, you want to get a serious intro text, like C++ from the ground up by Herbert Schild or the C++ programming language by Bjarne Stroustrup, once you get experienced.
Once you know C++, you're unstoppable and all other language become a cake to pick up, because most of the syntax will be C style. Good luck.
I'd use a gcc compiler before you learn Visual C++ (visual is for created windows form style apps, regular C++ is for console apps), just because it's easier to use for non-Visual part of C++, b/c with VC++ you'll need to create a new project every time or keep removing you CPP file from the project and creating a new one.
And to the poster above, your code in Visual Studio should begin something like this, namespaces are in, so use them!:
Code: |
#include <iostream> // no .h is necessary at the end, it's not ancient C++ or C!
using namespace std;
class c1 {
int i;
public:
void load_i(int val) { this->i = val; } // same as i = val
int get_i() { return this->i; } // same as return i
} ;
int main() {
// Code here
c1 myClass(10); // Initialize an instance of the c1 class
cout << myClass.get_i(); // Print content of myClass i var
return 0;
}
|
|
|
Back to top |
|
 |
Page 2 of 2 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|