字符串和指针位置
Strings and Pointer locations
我正在开发一个程序,该程序需要筛选一个充斥着 HTML/XML 垃圾.txt文件,以查找末尾有一个数字的特定模式。此模式应出现 10 次。模式如下:"<p class="wx-temp"> 93.
" 93 是一个温度读数,我最终试图收获什么,但是,我找不到一种方法将 93 与字符串的其余部分隔离开来,因为它会随着程序理想运行的每一天而变化。我一直在尝试找到一种方法来定义一个不能常量的整数数据类型,(即我不能在字符串末尾输入 93,因为它会破坏目的)并将其放在字符串或类似的东西中,我可以在模式结束后设置为 X 个字符开始, 换句话说,指针位置。对不起,漫无边际。有人可以帮助我吗?
假设您已将整个文件加载到单个字符串中,这并非不合理。
string html;
//(Some code that reads into a big string)
现在您只需要查找该标签。
string delimiter( "<p class="wx-temp">" );
vector<int> temperatures;
size_t pos = html.find_first_of(delimiter);
while( pos != string::npos )
{
// Skip past the tag (to the temperature)
pos += delimiter.size();
if( pos >= html.size() ) break;
// Extract it (C-style) and chuck it into the vector.
int temperature = atoi( html.c_str() + pos );
temperatures.push_back(temperature);
// If you want to stop after the first 10:
if( temperatures.size() == 10 ) break;
// Find the next tag
pos = html.find_first_of(delimiter, pos);
}
相关文章:
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- C++指针数组到字符数组中的特定位置
- 声明指针时更改星号的位置
- 如何在单个链表中交换两个节点的位置,只修改指针
- 当原始数据是常量时,修改指针指向的位置是 UB 吗?
- 如果访问对象,则指向的对象内部的指针会更改内存位置
- 访问违规读取位置传递指针以在c中写入的DLL中起作用
- 如何在内存位置取消指针,并用值启动它
- C++ - 智能指针 - 访问冲突读取位置0xDDDDDDDD
- 最简单的方法使多个指针一次指向同一位置,一次只处理2个位置
- 在指针中保存确定的位置
- 通过在此指针上放置新位置重新初始化对象时未定义的行为
- Visual Studio 中的"指向引用的指针"错误不会按发生位置的文件名显示
- 将指针数组传递给数组,以便在 malloc() 发生的位置发挥作用
- 为什么在递增后使用 [] 运算符访问指针数组会返回错误地址的当前内存位置
- 试图读取AIFF文件意外错误与指针位置等有关
- 使用指针在字符串中获取字符的位置
- qtextstream弄乱了其位置指针
- 我如何知道一个位置指针在二维数组的行数
- 修正:访问冲突读取位置(指针到字符串数组)