문제

Given the definition of ci_string from cpp.reference.com, how would we go about implementing operator>>? My attempts at it involved std::read, but it doesn't seem to work (that is, gcount() properly counts the number of characters entered, but there is no output)

#include <iostream> 
#include <cctype> 
#include <string> 

// ci_string definition goes here 

std::istream& operator>>(std::istream& in, ci_string& str)
{
    return in.read(&*str.begin(), 4); 
} 

int main()
{
    ci_string test_str; 
    std::cin >> test_str; 
    std::cout << test_str; 
    return 0; 
} 
도움이 되었습니까?

해결책

How about

std::istream& operator>>(std::istream& in, ci_string& str)
{
    std::string tmp;
    in >> tmp;
    str.assign( tmp.begin(), tmp.end() ); 
    return in;
} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top