我参照上面内容已经做出来了,但是用string代替char,编译没有通过,不知道怎么回事?c++ primer 上介绍文件操作的第二十章上,ifstream的参数明明用的是string。出错信息:e:\tmp\tmp4\tmp4.cpp(16) : error C2664: '__thiscall std::basic_ifstream<char,struct std::char_traits<char> >::std::basic_ifstream<char,struct std::char_traits<char> >(const char *,int)' : cannot convert parameter 1 from 'class std::basic_string<char
,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
我用的是VC6.0,代码如下,
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
To qyshooter:我试了你这种方法出下面的错误,为什么呢?
error C2678: binary '<<' : no operator defined which takes a left-hand operand of type 'char [100]' (or there is no acceptable conversion)