c++从文件中读取,跳过一些信息
C++ read from file, skipping some information
我需要一种读取以下文件的方法:
This is a line but not needed
This is another line not needed
name telephone
john 0000001
mark 0000002
.
.
.
我想跳过第一行,第三行是标题。我想把名字保存在一个字符串变量中,电话也保存在一个字符串变量中。数据之间有制表符
所以这是我的代码,但不能工作。
string line;
while (getline(infile, line))
{
istringstream iss(line);
int a, b;
if (!(iss >> a >> b))
{ break; } // error
// process pair (a,b)
}
所以我想知道如何跳过一些信息,如标题和解析变量中的信息。欢呼。
如果您继续从文件中读取,但只有在读取电话后才开始存储到字符串中呢?
像这样:
string str, newStr;
boolean = false;
while(cin >> str){
if(str.compare("telephone")== 0)
boolean = true;
if(boolean)
newStr += str;
}
return newStr;
确保为比较方法包含字符串
相关文章:
- 如何修复函数中的 fstream 文件输入以将正确的信息存储在结构数组中?
- 创建进行生产构建并创建调试信息的C++生成文件的最佳方法?
- 将对象信息保存到二进制文件中
- 错误 VSP1011:无法获取调试信息.与 /配置文件链接器开关链接
- Qt读取文本文件的一些信息
- 将文件信息(字符数组)嵌入到编译的二进制文件中
- 从带有 getline() 的文件读入一行上有多个信息得到无效参数错误
- 如何使用所有其他文件信息来编译代码,例如HAAR级联训练的权重的XML文件
- 是否可以将信息从XML文件转换为CPP
- 如何在文本文件中搜索员工记录(按名称)并仅显示其详细信息?
- 使用TDD时隐藏文件访问实现详细信息
- 生成有关编译的信息文件
- 如果我尝试将对话框从一个项目移动到另一个项目,我是否需要从 rc 文件中复制 DESIGNINFO、对话框信息和AFX_
- 在远程嵌入式设备上使用核心文件的 GDB - 如何获取有关回溯的更多信息?
- 接受多个输入(如 +、- 和平方数字)的计算器.从文本文件中提取信息
- 如何在 Windows 上从 C++11 统计信息对象的文件序列号中查找文件名
- 构建 vcxproj 文件给我一个无信息的错误"The system cannot find the path specified"
- 什么是阅读和将信息与此文本文件分开的好方法
- Fuse文件系统查找/Trash、/autorun.inf和/.xdg卷信息文件
- DWARF调试信息文件的diff工具