免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 824 | 回复: 0
打印 上一主题 下一主题

菜鸟的文件问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-01-10 11:59 |只看该作者 |倒序浏览
//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加了""后可以运行,不过还是不能完成任务,大家看看吧  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP