is there such a function

I want to know if there is such a function that can substitute the fragment:

Return_type function()
{
Return_type result;
cin >> result;
return result;
}

In other words I'm searching faster way to get a data from stdin? I'll use this function to fill the data in a priority_queue without using extra definitions of variables :

priority_queue<string> pq;
for (int i = 0; i < np; ++i)
pq.push(function() );

instead of:

priority_queue<string> pq;
for (int i = 0; i < np; ++i)
{
string curr;
cin >> curr;
pq.push(curr);
}
1
2
3
4
5
6
7
8
9
10
11
12
template<typename T>
T template_function()
{
T result;
cin >> result;
return result;
}


priority_queue<string> pq;
for (int i = 0; i < 10; ++i)
    pq.push(template_function<string>() );


http://www.colusplus.com/doc/tutorial/templates/
Thanks you :) But I mean is there such a function in the implementation of c++ or in some library like iostream?
No, your choice of a priority_queue() explicitly removes any such possibility.
Topic archived. No new replies allowed.