language: C++11 (gcc-4.7.2)
date: 222 days 11 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <array>
#include <cstring>
 
template<class e, class t, int N>
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, const e(&str_lit)[N]) {
    std::array<e, N-1> buffer; //get buffer
    in >> std::ws; //skips whitespace
    if (N)        
        in.read(&buffer[0], N-1); //read the rest
    if (strncmp(&buffer[0], str_lit, N-1)) //if it failed
        in.setstate(in.rdstate() | std::ios::badbit); //set the state
    return in;
}
template<class e, class t>
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, const e& char_lit) {
    e buffer;  //get buffer
    in >> buffer; //read data
    if (buffer != char_lit) //if it failed
        in.setstate(in.rdstate() | std::ios::badbit); //set the state
    return in;
}
//redirect mutable char arrays to their normal function
template<class e, class t, int N>
std::basic_istream<e,t>& operator>>(std::basic_istream<e,t>& in, e(&carray)[N]) {
        return std::operator>>(in, carray);
}
 
int main()
{
        int number;
        char character;
        char buffer[250];
        float thing;
        while (std::cin >> "begin " >> number >> 'a' >> character >> buffer >> thing)
                std::cout << number << ' ' << character << ' ' << buffer << ' ' << thing << '\n';
        std::cout << "Failed to read";
        return 0;
}