Connecting Tech Pros Worldwide Help | Site Map

from std::string to std::istream?

Gernot Frisch
Guest
 
Posts: n/a
#1: Jul 23 '05
Can I convert a std::string to a std::istream object?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}



Donovan Rebbechi
Guest
 
Posts: n/a
#2: Jul 23 '05

re: from std::string to std::istream?


On 2005-03-17, Gernot Frisch <Me@Privacy.net> wrote:[color=blue]
> Can I convert a std::string to a std::istream object?[/color]

The question doesn't even make sense. What are you trying to do ?

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Victor Bazarov
Guest
 
Posts: n/a
#3: Jul 23 '05

re: from std::string to std::istream?


"Gernot Frisch" <Me@Privacy.net> wrote...[color=blue]
> Can I convert a std::string to a std::istream object?[/color]

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


Gernot Frisch
Guest
 
Posts: n/a
#4: Jul 23 '05

re: from std::string to std::istream?



"Victor Bazarov" <v.Abazarov@comAcast.net> schrieb im Newsbeitrag
news:nPqdnXLo7cBwMqTfRVn-pQ@comcast.com...[color=blue]
> "Gernot Frisch" <Me@Privacy.net> wrote...[color=green]
>> Can I convert a std::string to a std::istream object?[/color]
>
> 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.[/color]

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



Victor Bazarov
Guest
 
Posts: n/a
#5: Jul 23 '05

re: from std::string to std::istream?


"Gernot Frisch" <Me@Privacy.net> wrote...[color=blue]
> [...]
> Was it hard to understand?[/color]

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.
[color=blue]
> [...][/color]


Closed Thread