Overloading operator>> for case insensitive string

Posted by TheSOFan on Stack Overflow See other posts from Stack Overflow or by TheSOFan
Published on 2013-10-20T09:43:20Z Indexed on 2013/10/20 9:54 UTC
Read the original article Hit count: 224

Filed under:
|
|

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; 
} 

© Stack Overflow or respective owner

Related posts about c++

Related posts about case-insensitive