Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

[C++] Can't use System namespace in Visual C++ 2008

This topic is 3287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry about this but I can't figure out why the following line does not work in Visual C++ 2008:
using namespace System;
I keep getting the following error: error C2871: 'System' : a namespace with this name does not exist What have I done wrong here? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Well ... as far as I know there is no standard namespace called System in C++.
The standard namespace is std;

So try using namespace std; instead.

I believe System is a C# related namespace and it cannot work in C++.

Share this post


Link to post
Share on other sites
Quote:
Original post by Spa8nky
error C2871: 'System' : a namespace with this name does not exist

What have I done wrong here?

Exactly what the error message says: that namespace does not exist (or at the very least, it can't find it in the current scope).
Did you forget to include a header file, or are you confusing managed with unmanaged code?

Share this post


Link to post
Share on other sites
Quote:
Original post by Spa8nky
Sorry about this but I can't figure out why the following line does not work in Visual C++ 2008


Visual C++ 2008 is your IDE.

What programming language do you think you are using?

If you think you are using C++: C++ does not have a 'System' namespace by default. It does have a 'std' namespace for its standard library.

Share this post


Link to post
Share on other sites
Are you attempting to create a C++/CLI (sometimes incorrectly called "managed C++") application? If so, it appears as though you picked the wrong options during project generation (choose a CLR project).

Share this post


Link to post
Share on other sites
Ah I see. I thought I was being a bit stupid here.

How can I use the equivalent of Console::Writeline (Console.WriteLine [C#]) in C++.

http://msdn.microsoft.com/en-us/library/system.console.aspx

Is there a good way to display messages in an output window like the console?

Thanks.

Share this post


Link to post
Share on other sites
In C++? Use the standard console output object, std::cout:

#include <iostream>
int main() {
std::cout << "Hello, world!\n";
}

Share this post


Link to post
Share on other sites
Aha! Thanks.

Can I print variables alongside strings (in combination)?



std::cout << "\n Hello" , velocity;



But not a , obviously.

Share this post


Link to post
Share on other sites

#include <iostream>
int main() {
int x = 32;
std::cout << "The value of x is:" << x << "\n";
}


Your questions suggest a lack of understand of the fundamentals of C++. Perhaps you should consider getting a book (it's free) to familiarize yourself with the language.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!