- 论坛徽章:
- 0
|
//CheckFor.cpp 判断一个磁盘文件中是否含有词 "nuclear" 或 "atomic energy"
// ASSUMPTION: 磁盘文件中至少包含一个词
#include <iostream>;
#include <fstream>;
#include <string>;
using namespace std;
const string word = "nuclear";
const string phrase = "atomic energy";
void main()
{
string line, filename;
ifstream infile;
cout << "enter a filename: ";
cin >;>; filename;
infile.open(filename);
while (getline(infile, line))
{
if ( line.find(word, 0) < line.max_size() )
cout << "WORD FOUND! " << endl;
else if ( line.find(phrase, 0) < line.max_size() )
cout << " HRASE FOUND!" << endl;
}
cout << "file completely examined" << endl;
}
--------------------Configuration: 9_4 - Win32 Debug--------------------
Compiling...
9_4.cpp
C:\Documents and Settings\Administrator\桌面\临时文档\9_4.cpp(1 : error C2664: 'void __thiscall std::basic_ifstream<char,struct std::char_traits<char>; >;: pen(const char *,int)' : cannot convert parameter 1 from 'class std::basic_string<char,struc
t 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
Error executing cl.exe.
9_4.obj - 1 error(s), 0 warning(s)
这是课本程序,出了错误.那个filename加了""后可以运行,不过还是不能完成任务,大家看看吧 ![](static/image/smiley/default/icon_rolleyes.gif) |
|