Sign in to follow this  
Akill

Visual c++ express help!

Recommended Posts

Akill    122
I used to use Dev-cpp as my compiler. But the way people were going about it i thought it would be better to use visual c++. I got visual c++ express beta. To try it out i was just going to make a simple hello world script. But it is very differant from using Dev-cpp. when i managed to find my way around and get the script i got an error when building that iostream dosent exsist when i used #include <iostream.h> i tried #include <iostream> instead and then it kept giving me errors that cout was an invalid command, is there something i havnt done right? help me! ive probably been very bland on how ive done this so its hard to distingush a problem but if any1 who uses this could give a rundown on how to make a hello world script work that would be nice :) thx ppl

Share this post


Link to post
Share on other sites
Washu    7829
Did you remember to qualify the namespace cout is in?

#include <iostream>

int main() {
std::cout<<"Hello world."<<std::endl;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I downloaded MSVC Express Beta 1 yesterday, but I actually haven't tried it.

Your problem is the coding standard you use. I'm guessing you were taught, as I was, in the older ANSI standard. Older versions of MSVC (I havent tried MSVC.NET, but MSVC6 surely did) supported both older and newer standards. MingW, the compiler Dev-C++ uses, also supports both standards. The problem is, with the new standard, you have to allocate for namespaces. That is why when you call the cout function, you are getting an error since you haven't called it namespace-style. I suggest you go check out some tutorials on the newer C++ coding standard. Google is useful.

If you are worrying about a huge change in the language, don't worry. It's not like the jump from VB6 to VB.NET, its just a few minor things you have to learn to get used to.

Laters,

Share this post


Link to post
Share on other sites
evolutional    1393
Are you specifying using namespace std; or using std::cout? To me, the errors you're having sound typical of the lack of a namespace qualifier.

Your hello world program can look like this:


#include <iostream>

int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}




Or like:


#include <iostream>

using namespace std;

int main()
{
cout << "Hello, world!" << endl;
return 0;
}




In the second example, I've declared that I'm using the std namspace (to which cout and other functions belong) meaning that I can use the functions without explicitly stating the std namespace qualifier. If I omit the using declaration, I have to explicitly state the namespace.

Have a look at MSDN: using directive for more information

Share this post


Link to post
Share on other sites
Akill    122
thx guys for your quick replies! the info is really helpful, and would explain a few things. I'm going to try this out right now, expand my knowledge and hopefully keep myself up-to-date :S

thx again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this