简体   繁体   中英

Cant use std::istream::get

I want use the 6th implementation of std::istream::get(...) method. https://en.cppreference.com/w/cpp/io/basic_istream/get It takes basic_streambuf& and char_type. I write:

char quote = '\'';
std::stringstream str;
input.get(str, quote); //input is std::istream object

But compiler as if it doesn't see this implementation, it try convert stringstream to char*:

error C2664: 'std::basic_istream<char,std::char_traits> &std::basic_istream<char,std::char_traits>::get(_Elem *,std::streamsize)': cannot convert argument 1 from 'std::stringstream' to '_Elem *'

Couldn't find answer for this. What's wrong? Thanks for help

To get the streambuf associated with a std::stringstream , you need to call rdbuf() .

input.get(*str.rdbuf(), quote);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM