Page 1 of 1

Issue in declaratioin of "use namespace std;"

PostPosted: Mon Jul 15, 2013 1:00 pm
by Dora ji
Hi,

I am trying to execute C++ program on zos.I tried a "Hello world" program without using "use namespace std;" it executed well and i could able to see the output of it. But while including "use namespace std;" its not executing.Is this mandatory for a C++ program on Zos??

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Mon Jul 15, 2013 2:16 pm
by NicC
You say it is "not executing". What does that mean? That you have not tried to execute it? That it executes but does not give expected results? That it excutes but fails during execution? That it failed to compile and/or link? And do not just say - "oh. it was this" but show us what went wrong.

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Mon Jul 15, 2013 4:33 pm
by Dora ji
Sorry...

the basic C++ program which i executed on Zos is

#include <iostream.h>                             
 
int main()                           
{                                   
 cout << "Hello World!";             
 return 0;                           
}                   


the same program in which i have included the "using namespace std;" which is also a format for C++ program but while trying to execute it,this is not getting executed.


#include <iostream.h>   
using namespace std;           
 
int main()                           
{                                   
 cout << "Hello World!";             
 return 0;                           
}


The error which i got while trying this is,

The text "namespace" is unexpected. "using" may be undeclared or ambiguous.

How to rectify it??

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Mon Jul 15, 2013 4:50 pm
by NicC
Not being a "curly-whirly" language programmer I am not sure about this but...from Googling 'using namespace std;' and the checking out a hit on the first page it may be that your using conflicts with your #include.

Edit [rest of post deleted as I am probably talking rubbish!}

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Mon Jul 15, 2013 6:06 pm
by Dora ji
sorry i cant able get it properly.

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Mon Jul 15, 2013 6:25 pm
by Robert Sample
The z/OS XL C/C++ Language Reference manual indicates your posted source is not properly coded:
9.7 Unnamed namespaces
A namespace with no identifier before an opening brace produces an unnamed namespace. Each translation unit may contain its own unique unnamed namespace. The following example demonstrates how unnamed namespaces are useful.

#include <iostream>

using namespace std;

namespace {
const int i = 4;
int variable;
}

int main()
{
cout << i << endl;
variable = 100;
return 0;
}


In the previous example, the unnamed namespace permits access to i and variable without using a scope resolution operator.

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Wed Jul 17, 2013 12:49 pm
by Dora ji
Hi,

I tried for the program which you have given, but the same error prevails (The text "namespace" is unexpected. "using" may be undeclared or ambiguous).

The "std" is not recognised.

Do i need to include anything in the system libraries to recognise the "std" ??

Re: Issue in declaratioin of "use namespace std;"

PostPosted: Tue Jul 30, 2013 8:39 am
by mwilliams
Well,
the question is, how are you compiling?
Are you compiling as for c program, using the EDCC proc, or you compiling for a C++ program, using the CBCC proc?
Please note, the C only compile option does not recognize elements of the C++.