PDA

Click to See Complete Forum and Search --> : C++ and Visual C++


SomethinCool
Jan 29th, 2002, 02:21 PM
what is the difference between C++ and Visual C++...i heard it's like the difference between Qbasic and Visual Basic....almost.

chilibean
Jan 29th, 2002, 03:29 PM
Visual C++ is a programming environment and compiler, but C++ is a language. You can use C++ in other compliers besides Microsoft's (Borland's, Dev-Cpp, etc.). You pay for (or steal) Visual C++, but C++ is always free. Visual C++ also adds MFC to make things easier and defines some other Microsoft specific things. You can think of Visual C++ as the program that helps you write and edit C++ code.

SomethinCool
Jan 29th, 2002, 03:42 PM
what is a MFC, i dont think i've ever heard of that.

also i am new to C++ all i can do is stuff like:


#include "iostream.h"

void main()
{
cout << "Pick a number: ";
int number;
cin >> number;
cout << "Your number was: " << number;
}

chilibean
Jan 29th, 2002, 04:02 PM
MFC stands for Microsoft Foundation Classes. They are used to make it easier to work with windows, and controls - much like Visual Basic. If you are a beginner with C++ you should probably not use them right away - learn the API first. Other users on this board will agree that it is better to learn how to create programs with the plain API before using MFC to make it easier. The API stands for the Application Program Interface and is what MFC uses anyway. It allows you to create windows and controls using lower level code.

See the Tutorials link at the top of the C/C++ forums for more info.

SomethinCool
Jan 29th, 2002, 04:11 PM
yeah i know a lot about VB but not enough of C++ so i want to move on to the more professional language (or the language that most companies use).

How do the API's work in C++? are they the same as the API's in VB?

chilibean
Jan 29th, 2002, 04:22 PM
The API is the same in C++ as in VB, except that the variables look a little different (there's pointers and structs) and you never need to declare the function ahead of time - you just include windows.h which does this for you automatically. So yes, if you know the API in VB you already have a head start in C++ because you can use some of the same code for API calls (with some changes of course).

parksie
Jan 29th, 2002, 04:54 PM
Originally posted by SomethinCool

#include "iostream.h"

void main()
{
cout << "Pick a number: ";
int number;
cin >> number;
cout << "Your number was: " << number;
}
Since you're new, I'll be nice :)

1. You should use angle-brackets not quotes: #include <iostream.h> since it's a system header.

2. You should be using the iostream header, not iostream.h which is the older version.

3. It's int main, not void.

4. You should have an endl after the last output of number. This puts a newline and flushes the output buffer so that anything else doesn't get mixed up with your program's output.

So, this is a corrected version:#include <iostream>

using namespace std; // You need this for the new headers

int main() {
cout << "Pick a number: ";
int number;
cin >> number;
cout << "Your number was: " << number << endl;

return 0; // To go with the new function definition
}The using namespace std; is something that you need for the standard c++ library, and you'll find out why it's important later on :)

made_of_asp
Jan 29th, 2002, 07:01 PM
Yeah API is simple


#include <windows.h>

float x;
x = GetTickCount(); //Api Function


Parskie: whats so special about std namespace?? yet i did not discover any features in new versions.

SomethinCool
Jan 29th, 2002, 08:11 PM
Since you're new, I'll be nice

1. You should use angle-brackets not quotes: #include <iostream.h> since it's a system header.

2. You should be using the iostream header, not iostream.h which is the older version.

3. It's int main, not void.

4. You should have an endl after the last output of number. This puts a newline and flushes the output buffer so that anything else doesn't get mixed up with your program's output.


well..i usually put the angle brackets but i just dont care which ones i use.

in my C++ book that i have from school, (i'm only in 10th grade), it says to use void main(). Why should i use int main? i saw that somewhere also. Doesnt that declare it as an integer?

ok i will put endl at the end..i saw that also in a tutorial.


also...with that API


#include <windows.h>

float x;
x = GetTickCount(); //Api Function


you dont even have to do stuff like:

Private Declare Function GetTickCount lib "kernel32.dll" () as long

are the API's for windows all in that windows header file?

SomethinCool
Jan 29th, 2002, 08:14 PM
also, one last thing....

how hard is it to make Windows Apps in C++

and.....

i want to get into graphics programming with C++ using DirectX, now, i've seen tutorials for DirectX in VB and that looks sorta hard. Is it easier to make DirectX programs in C++ or VB?

Sorry for the long post.

Wynd
Jan 29th, 2002, 08:15 PM
SomethinCool: Basically, you can think of it in these simple terms:

:) C++: A programming language, such as C, Delphi, Java, etc.

:) Visual C++: An IDE (integrated development environment) for C++. Some others are Dev-C++, Borland C++, etc.

:) MFC: Microsoft Foundation Classes. These help simplify window creation and the like, but are on the slow side. Note: some people call code with MFC in it Visual C++ code, so don't be fooled ;)

Made_of_asp: Not sure, but I think the std namespace and the standard headers are used for compatability on other platforms, where iostream.h can have compiler-specific things. Again, I'm not sure, maybe someone can clarify :)

Wynd
Jan 29th, 2002, 08:19 PM
Originally posted by SomethinCool


well..i usually put the angle brackets but i just dont care which ones i use.

in my C++ book that i have from school, (i'm only in 10th grade), it says to use void main(). Why should i use int main? i saw that somewhere also. Doesnt that declare it as an integer?

ok i will put endl at the end..i saw that also in a tutorial.


also...with that API


#include <windows.h>

float x;
x = GetTickCount(); //Api Function


you dont even have to do stuff like:

Private Declare Function GetTickCount lib "kernel32.dll" () as long

are the API's for windows all in that windows header file?
1. Angle brackets are for headers that come with the compiler (iostream for example). Quotes are for headers that are in the same directory as the source file, usually headers that you write yourself.

2. See this thread (http://www.vbforums.com/showthread.php?s=&threadid=137930) for an explanation.

3. You only have to include windows.h because all the API functions are already declared in it.

Zaei
Jan 29th, 2002, 08:41 PM
It should, actually be:

unsigned long x;
x = GetTickCount();

As for the angle brackets, i read this in a C programming book, but it should be the same for C++. The double quotes tell the compiler to look in the currect directory, THEN in the standard directories, while the angle brackets ignore the current directory, and simply look in the standard directories.

int main() is the correct way to define your main function. In fact, the correct way is (correct me if im wrong) int main(char* argv[], int argc), which allows you to parse command line arguments. Dont worry about that for now.

Namespaces are a C++ feature that allows you to encapsulate things in a common area. For example, when using classes, if you define an enum inside of the class, you access it through the class:

class x {
public:
x();
enum { a, b, c };
};

...

x::a;


Notice the double colons, which specify the scope of the enumeration. Namespaces are the same, except they add another layer of scope:

namespace myNamespace {

class x {
public:
x();
enum { a, b, c };
};
};
...

myNamespace::x::a;


Now, that is a lot to type. So, instead of typing all of that every time you use something, you tell the compiler to look in that namespace for things it cant find, like this:

using namespace myNamespace;

You could also do:

using myNamspace::x

to use class x without the myNamespace:: part, but not import the rest of the namespace.

The whole reason for namespaces is to prevent name duplication, so you may or may not want to import the entire namespace.

Z.

PS: I think that all of the above is correct, but it may not be =).

made_of_asp
Jan 29th, 2002, 08:42 PM
C++ makes everything harder than VB. Building Win32 GUI App's from scratch isn't easy, but there are dialogs resources that can help. mfc requires some runtimes that even i don't have installed.

MFC: :( for true C++ App, don't use MFC. Raw API is a good solution to creating app's + you lean how to use WM's.

SomethinCool
Jan 29th, 2002, 08:46 PM
ok how would you program a Win32 App using Raw API?

SteveCRM
Jan 29th, 2002, 08:54 PM
Im telling you right now you're not ready for it. You should really get the basics down first...

check out www.cprogramming.com they have some good tutorials.

:)

made_of_asp
Jan 30th, 2002, 03:37 AM
if you want to try win32 app's in VC++,


Visual C++ can create the main stuff for you. Visual C++ -> File/New -> Projects Tab -> Win32 Application -> OK -> A Typical Hello World Application

VC++ will create necessary code for a win32 window + some cursors, icons , string table, about dialog and some other stuff.

VC++ will create some message handlers including WM_DESTROY, WM_COMMAND, WM_PAINT.