读书人

高手来看下是为什么!解决办法

发布时间: 2012-02-07 17:45:36 作者: rapoo

高手来看下是为什么!
#include <string>
#include <fstream.h>
#include <stdlib.h>
using namespace std;
void main()
{
string s;
cin> > s;
ifstream fin(s.c_str());
}


--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\xuewenjie\Cpp1.cpp(8) : error C2679: binary '> > ' : no operator defined which takes a right-hand operand of type 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > ' (or there is no accep
table conversion)
C:\Documents and Settings\xuewenjie\Cpp1.cpp(9) : error C2872: 'ifstream ' : ambiguous symbol
Error executing cl.exe.

Cpp1.exe - 2 error(s), 0 warning(s)

[解决办法]
混用了标准库的新旧格式。这样写:

#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;

[解决办法]

> > 符号需要重载!
[解决办法]
#include <string>
#include <fstream.h>
#include <stdlib.h>
#include <iostream> // 你没有包含这个文件,在我机器上提示的错误是cin没有定义
// 还有一个warning:#include <fstream.h> 中包含了至少一个冲突的头文件或者过时的头文件.
// 最好的办法是如楼上所说,用新格式的头文件
/*
#include <string>
#include <fstream>
#include <cstdlib>
#include <iostream>
*/

using namespace std;

int main()
{
string s;
cin> > s;
ifstream fin(s.c_str());
cout < < s < < endl;

return 0;
}

读书人网 >C++

热点推荐