Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get around not being able to use using namespace std; in C++

Tags:

c++

linux

gcc

hp-ux

I've encountered this issue while trying to port my C++ source code from HP-UX to Linux. When I try to compile the C++ source code on Linux, what happens is that it complains that components (from the standard C++ library) don't exist. Placing the line using namespace std; at the top of the source code seems to fix the problem. When I try to recompile the code on HP-UX, the aCC compiler complains that only namespace names are valid here ( it doesn't consider std a valid namespace ). I was wondering if there was a way to get around this issue so that the source code is binary compatible with both HP-UX's long deprecated C++ compiler and LINUX's GCC compiler.

like image 616
Justin Avatar asked Dec 26 '22 23:12

Justin


2 Answers

This sucks, but you can do this:

#ifndef __HP_aCC
using namespace std;
#endif

Defines from here, and I have no way to verify.

like image 112
Matt K Avatar answered Jan 04 '23 23:01

Matt K


You could use pre-proccessors to check for the OS and whether or not to include namespace std; So if your OS is not HP aCC, it doesn't includes std, otherwise it does. Like so:

#ifndef __HP_aCC
using namespace std;
#endif

or if you want to check for linux and win and only use namespace std if its those OS; you can also do it like this:

#if defined(WIN32) || defined(LINUX)
using namespace std;
#endif

Hope that helped!

like image 42
Rivasa Avatar answered Jan 05 '23 00:01

Rivasa