Want workaround for msvc compiler (VC++ 6.0).

J

Jason Heyes

I compile this program using Microsoft Visual C++ 6.0:

#include <cstdio>

int main()
{
std::printf("Hello world");
return 0;
}

It gives me the following error message:

Main.cpp
C:\Projects\Examples\Main.cpp(5): error C2653: 'std': is not a class or
namespace name

How do I stop this? Thanks.
 
P

Phil Staite

Apparently v6.0 doesn't put printf in the std namespace then. You could the
traditional C program:

#include<stdio.h>

int main(int argc, char* argv[])
{
printf("Hello World\n");
return 0;
}

But in C++ it would look more like:

#include<iostream>

int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
 
J

Jason Heyes

Phil Staite said:
Apparently v6.0 doesn't put printf in the std namespace then. You could
the
traditional C program:

#include<stdio.h>

int main(int argc, char* argv[])
{
printf("Hello World\n");
return 0;
}

But in C++ it would look more like:

#include<iostream>

int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}

Unfortunately v6.0 puts nothing from C in the std namespace. Example:

#include <iostream>
#include <cstdlib>

int main()
{
char c;
std::cin >> c;
std::cout << "Character is " << (std::isupper(c) ? "upper" : "lower") <<
" case" << std::endl;
return 0;
}

This generates the same error.
 
P

Panjandrum

Jason said:
Unfortunately v6.0 puts nothing from C in the std namespace. Example:

#include <iostream>
#include <cstdlib>

int main()
{
char c;
std::cin >> c;
std::cout << "Character is " << (std::isupper(c) ? "upper" : "lower") <<
" case" << std::endl;
return 0;
}

This generates the same error.

Because isupper is probably a macro.
 
D

Default User

Jason said:
I compile this program using Microsoft Visual C++ 6.0:

#include <cstdio>

int main()
{
std::printf("Hello world");
return 0;
}

It gives me the following error message:

Main.cpp
C:\Projects\Examples\Main.cpp(5): error C2653: 'std': is not a class or
namespace name

How do I stop this? Thanks.

VC++6 is broked in this regard, at least in the version you (and it
turns out I) have. The most portable work-around is to not use the new
header, but the "C compatibility" version.

#include <stdio.h>

int main()
{
printf("Hello world\n");
return 0;
}


That header is deprecated, but is liable to be part of the standard for
a long time to come. BTW, I added a new-line to the output string, you
should have that in yours as well.



Brian
 
M

Mike Smith

Jason said:
I compile this program using Microsoft Visual C++ 6.0:

#include <cstdio>

int main()
{
std::printf("Hello world");
return 0;
}

It gives me the following error message:

Main.cpp
C:\Projects\Examples\Main.cpp(5): error C2653: 'std': is not a class or
namespace name

How do I stop this? Thanks.

How 'bout:

namespace std {
#include <cstdio>
} // namespace

Note that I haven't tried this myself...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top