C++:查找一本书的章节
C++: Finding the chapter of a book
我有一个相当大的文本文件,希望有一个C++程序扫描它并返回我想要的章节。例如,假设该文件名为"MyTales.txt",其内容为
MYTALE by Me (classifying what book it is)
CHAPTER ONE
Part 1: The Start
其中Part 1
(整体)是要返回的节。
作为一个基本模板,到目前为止我想到的是:
#include<iostream>
#include<fstream>
ifstream in;
ofstream out;
string book, chapter, part;
int main() {
cout << "Please enter the part to locate:nBook: ";
cin >> book;
cout << "Chapter: ";
cin >> chapter;
cout << "Part: ";
cin >> part;
in.open("MyTales.txt");
while (in >> data) {
// where data is assigned
}
out.open("BookParts.txt");
out << data;
in.close();
out.close();
}
我只是不知道如何正确分配"数据"。我修改了一些字符串函数和其他东西,但似乎什么都没用。非常感谢您的帮助!
第一个问题是根据其数值生成章节的标题。获得名称后,忽略包括章节名称在内的逐行输入。然后阅读输入,直到你遇到一行以"Chap章"开头或输入的末尾。最后输出你读到的所有内容。
相关文章:
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 查找矩阵C++中每一列和每一行的最小和最大元素
- 程序以使用 C++ 中的 while 循环查找一组数字的最小值
- 一种有效的数据结构,用于按 ID 访问和查找加权随机项
- 如何从一组变量中查找最低值
- 如何通过查找迭代器结果分配给一组对的元素
- C++ 查找算法:如何找到元素的最后一次出现?
- 需要帮助从12个字节生成新的24字节RGB查找阵列,或者是一种更好的编码方法
- armadillo c :如何使效率分配到一本
- 在 C 中创建一种查找表
- 正在寻找一本关于windows C++GUI编程的书
- 如果不使用C++11,安东尼威廉的"C++ Concurrency in action"是一本合适的书吗?
- 有人能推荐一本关于可移植C/C++代码开发的书吗
- 一本优秀的C++书,适合中级程序员成为专业程序员
- 读一本c++ 11的书需要有c++98的知识吗?
- 请推荐一本有价值的关于多线程和boost的书.线程或c++ 11
- 如何存放一本英语字典
- C++:如何制作一本简单的词典
- 一本高效的字符串词典
- 请推荐一本反设计模式的电子书