Roman
Roman

Reputation: 9451

How to import multiple members of same namespace in single line using C++?

I am a python programmer, and just learning some C++ on the side.

From what I understand, in C++ using namespace std
would be equivalent to python's from std import *, and should not be used.

1) Correct?

And then in Python, I could do for example from std import cout, cin.

2) Is there a single line equivalence? Or would I have to do it in multiple lines?

using std::cout;
using std::cin;

Upvotes: 2

Views: 1047

Answers (2)

user8966388
user8966388

Reputation: 11

Yes , there is one way you can import multiple members but its not supported everywhere.

using std::cout,std::endl;

But you will get a warning.

warning: comma-separated list in using-declaration only available with -std=c++1z or -std=gnu++1z using std::cout,std::endl; ^

Upvotes: 1

VP.
VP.

Reputation: 16755

Shortly:

  1. Correct.
  2. There is no any single line equivalent for this.

Upvotes: 3

Related Questions