读书人

ifstream的奇怪有关问题

发布时间: 2012-04-11 17:42:33 作者: rapoo

ifstream的奇怪问题
我只是像依据文件是否在命令行里给出,来判断使用STDIN还是打开文件:

C/C++ code
    bool pair_end;    istream* IN_A_P = NULL;    istream* IN_B_P = NULL;    ostream* OUT_P  = NULL;    if (file_a==NULL) {        // from STDIN        if (file_b==NULL) {            pair_end = false;            IN_A_P = &cin;        }        // from file b        else {            pair_end = false;            IN_A_P = new ifstream(file_b);        }    }    else {        // from file a        if (file_b==NULL) {            pair_end = false;            IN_A_P = new ifstream(file_a);        }        // from both file        else {            pair_end = true;            IN_A_P = new ifstream(file_a);            IN_B_P = new ifstream(file_b);        }    }

然后为啥有这样的问题?
/home/yangxi/projects/HTQC/ht_stat.cpp:155:41: error: invalid use of incomplete type ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/iosfwd:113:11: error: declaration of ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/home/yangxi/projects/HTQC/ht_stat.cpp:162:41: error: invalid use of incomplete type ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/iosfwd:113:11: error: declaration of ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/home/yangxi/projects/HTQC/ht_stat.cpp:167:41: error: invalid use of incomplete type ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/iosfwd:113:11: error: declaration of ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/home/yangxi/projects/HTQC/ht_stat.cpp:168:41: error: invalid use of incomplete type ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/iosfwd:113:11: error: declaration of ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/home/yangxi/projects/HTQC/ht_stat.cpp:172:52: error: invalid use of incomplete type ‘std::ofstream {aka struct std::basic_ofstream<char>}’
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../include/c++/4.6.2/iosfwd:116:11: error: declaration of ‘std::ofstream {aka struct std::basic_ofstream<char>}’


[解决办法]
包含了 <fstream> 这个头文件了没?

读书人网 >C++

热点推荐