我如何从文本文件中读取...? [英] How Can I Read From A Text File...?

查看:43
本文介绍了我如何从文本文件中读取...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多单词的文本,例如我想从文本文件中找到并打印一个单词Crow....我应该使用哪个函数在c ++中使用文件处理在屏幕上查找和打印

I have a text which contains a lot of words, For example i want to find and print a word "Crow" from text file....which function should i use to find and print on screen using file handling in c++

推荐答案

// reading a text file
#include < iostream > 
#include < fstream >
#include <string >
using namespace std;
 
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';
}
myfile.close();
}
 
else cout << "Unable to open file"; 
 
return 0;
}


尝试

http://www.youtube.com/watch?v=s3-DmI1ZWxE [ ^ ]

http://www.dreamincode.net/forums/topic/109268-string-search-in-a-file/ [ ^ ]


这篇关于我如何从文本文件中读取...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆