from std::string to std::istream?

V

Victor Bazarov

Gernot Frisch said:
Can I convert a std::string to a std::istream object?

No. But you can create an std::istringstream object with it:

std::string mystring("1 2 3");
std::istringstream is(mystring);
int one, two, three;
is >> one >> two >> three;

Of course, my effort is wasted if that's not what you wanted. Next
time please be more verbose trying to explain what you need instead
of asking about legality of a potential solution to your task.

V
 
G

Gernot Frisch

Victor Bazarov said:
No. But you can create an std::istringstream object with it:

std::string mystring("1 2 3");
std::istringstream is(mystring);
int one, two, three;
is >> one >> two >> three;

Of course, my effort is wasted if that's not what you wanted. Next
time please be more verbose trying to explain what you need instead
of asking about legality of a potential solution to your task.

Was it hard to understand?
Problem is: I have a function:

bool Read(ifstream&is)
{
}

and I changed it to:
bool Read(istram& is)
{
}

because I don't have a file to read from, but a string in memory. So,
your solution is exactly what I need, I guess.

Thanks a lot,
Gernot
 
V

Victor Bazarov

Gernot Frisch said:
[...]
Was it hard to understand?

Yes, it was. And we are not here to make guesses. Try to avoid posting
riddles and instead explain your problem as verbosely as you can. Even
if it takes extra five minutes of your precious time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top