查找并提取文件中的某个值
Find and extract a certain value in a file
做一个需要加载现有文件的项目,我想知道如何提取某个值,例如:
如果文件Joe Shmoe包含:
Here is your information:
Name: Joe Shmoe
Address: 123 Street St
Balance: $300
我怎样才能将 Joe Shmoe、123 Street St 和 300 提取到单个变量中?(不知道为什么有些词是蓝色的,它们只是应该是正常的(
std::getline
和ignore
的小解释,in
总是一个输入流。
std::string s;
char c = 'n';
std::getline(in, s, c);
读取当前行的其余部分(因此最多c
个(。读取部分从in
中删除,除c
之外的所有内容都放入s
。如果不提供c
,将使用默认'n'
(行尾(。
std::streamsize len = 1;
int c = -1; // You can also take a char and write for example char c = 'n' to ignore to the end of the line.
in.ignore(len, c);
将从in
中删除最多len
个字符。如果它到达c
,它就会停止(-1
说它永远不会在这条路上停下来(。默认值如上,但通常使用len = std::numeric_limits<std::streamsize>::max()
(输入参数可以具有的最大值(和char c = 'n'
。然后它基本上会做std::getline(in, s)
会做的事情,但丢弃字符串(它实际上永远不会创建它(。
相关文章:
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- C++(.cpp文件和.h文件)拆分代码并添加一个函数,提取 - 这很容易吗?
- 如何从也包含C++字母的文本文件中提取某些数字?
- 使用从文件(stod、strtod、atof)中提取的数据C++从字符串转换为双精度.csv
- JPG-如何从ICC配置文件部分APP2读取/提取数据
- 遍历对象向量,并找到与从文本文件中提取的对象匹配的变量
- 如何使用 WINAPI 和 C++ 提取可执行文件的文件描述?
- 查找并提取文件中的某个值
- 如何从txt文件c++中提取括号之间的数字
- 在Linux Mint 19下,从哪里提取wxWidgets的源代码(.cpp文件)用于步骤内部调试
- 如何将ASCII数字转换为从文件中提取的整数
- 从zip文件中提取文件夹
- 从Windows模块中的资源中提取文件
- 从zip中提取文件
- 使用LibTar提取文件
- 如何从文件中提取文件属性/元数据/注释?
- 在c++中使用COM从zip文件中提取文件
- 如何从虚拟磁盘中提取文件
- 如何从c++程序中提取文件,然后从其中运行一个
- 从资源中提取文件,文件大小错误