Visual c++ express help!

Started by
4 comments, last by Akill 19 years, 4 months ago
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
Advertisement
Did you remember to qualify the namespace cout is in?
#include <iostream>int main() {  std::cout<<"Hello world."<<std::endl;}

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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,
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
http://www.paulgrenyer.co.uk/articles/writing_hello_world_with_microsoft_visual_studio.html

i am new to visual studio and this helps a ton
Grim_reaper7Lamp Geekz
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!

This topic is closed to new replies.

Advertisement