Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Is there a way to extract data from an ifstream directly into a parameter? I will demonstrate what I mean:

C++
// Normal method
ifstream yeet("yeet.txt");
string kek;
yeet >> kek;
print(kek);

// What I am trying to do, to some effect
ifstream yote("yote.txt");
print(yote.extract<string>());


Is anything like this built into filestreams (or streams in general)?

Thanks!

What I have tried:

So far I'm using the normal method, but it seems really messy.
Posted
Updated 20-Jan-19 21:18pm
Comments
CPallini 19-Jan-19 13:50pm    
Why do you find it 'messy'?
Anyway you may write a function for that, if you like.
Richard MacCutchan 20-Jan-19 3:58am    
No, it's not messy, it's quite logical. Remember, ifstream is basically just a class, so you could enhance it yourself if you want more specialisations.

1 solution

If you intended to copy a file, maybe you should use std::streambuf instead. There's a good code example here: streambuf::sgetn - C++ Reference[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900