Issue in declaratioin of "use namespace std;"



Help for C/C++ for MVS, OS/390 C/C++, z/OS C/C++ and C/C++ Productivity Tools for OS/390

Issue in declaratioin of "use namespace std;"

Postby Dora ji » Mon Jul 15, 2013 1:00 pm

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??
Dora ji
 
Posts: 12
Joined: Sun Jul 07, 2013 11:12 pm
Has thanked: 0 time
Been thanked: 1 time

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

Postby NicC » Mon Jul 15, 2013 2:16 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby Dora ji » Mon Jul 15, 2013 4:33 pm

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??
Dora ji
 
Posts: 12
Joined: Sun Jul 07, 2013 11:12 pm
Has thanked: 0 time
Been thanked: 1 time

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

Postby NicC » Mon Jul 15, 2013 4:50 pm

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!}
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

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

Postby Dora ji » Mon Jul 15, 2013 6:06 pm

sorry i cant able get it properly.
Dora ji
 
Posts: 12
Joined: Sun Jul 07, 2013 11:12 pm
Has thanked: 0 time
Been thanked: 1 time

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

Postby Robert Sample » Mon Jul 15, 2013 6:25 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

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

Postby Dora ji » Wed Jul 17, 2013 12:49 pm

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" ??
Dora ji
 
Posts: 12
Joined: Sun Jul 07, 2013 11:12 pm
Has thanked: 0 time
Been thanked: 1 time

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

Postby mwilliams » Tue Jul 30, 2013 8:39 am

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++.
mwilliams
 
Posts: 11
Joined: Thu Feb 07, 2013 8:55 am
Has thanked: 0 time
Been thanked: 1 time


Return to C, C++

 


  • Related topics
    Replies
    Views
    Last post