C 检查数据是否已指定字符串
C++ Checking if data has specified string
,因此我试图检查字符串是否在内存的'块中。因此,这是我开始并想从。
开始检查的编织内存地址0x00343211
。
我要做的是将从0x00343211
到0x00343211 + 900
的数据写入一个char数组,然后检查该字符串是否正在寻找。
所以这就是我已经尝试过的
char dataBuf[1000] = { 0 };
memcpy((void*)dataBuf,(void*)0x00343211,900);
if(strstr(dataBuf,"ACTIVE") != NULL)
{
//I want to check if the string "ACTIVE" is
//within the random data that I have written into dataBuf
}
但这似乎不起作用。
您可以直接在内存块上使用std ::搜索,并祈祷您的编译器具有有效的实现,例如:
#include <algorithm>
#include <string>
#include <iostream>
int main()
{
char dataBuf[13] = { "xxxACTIVExxx" }; // block of 12 bytes + zero byte
std::string active = "ACTIVE";
using std::begin;
using std::end;
// std::search returns dataBuf+12 if no match is found
if (std::search(dataBuf, dataBuf + 12,
begin(active), end(active))
!= dataBuf + 12)
{
std::cout << "ACTIVE has been foundn";
}
else {
std::cout << "ACTIVE has not been foundn";
}
return 0;
}
相关文章:
- C++-字符串是否包含一个带有简单循环的单词
- 将常量字符串添加到非常量字符串是否会给出常量字符串
- 检查字符串是否"null" C++
- 使用XOR查找O(n)-解决方案中的两个字符串是否为变位符
- 检查字符串是否为整数
- 使用 SET(C++) 检查两个给定字符串是否是字谜时出现运行时错误
- 如何检查字符串是否正确以将其转换为 int?
- 程序检查字符串是否只包含 1 和 0?
- 检查字符串是否是拉平德罗姆
- 尝试使用 indexOf 创建一个 if 语句来检查字符串是否包含字符.有一点麻烦
- 通过默认复制构造函数比较 C++ 字符串是否会影响性能,原因为何?
- gtest:检查字符串是否等于两个字符串之一
- 如何检查字符串是否包含所有这些:数字、字母和特殊字符
- 如何检查字符串是否以C++中的"ed"结尾;
- 字符串是否在其构造函数中复制数据
- 检查字符串是否是数字,然后将该数字转换为 int?
- 如何检查一个字符串是否包含多个其他字符串?
- 检查字符串是否仅包含字母
- 如何根据一个特定字母的出现来确定两个字符串是否相等?
- 查找字符串是否包含字符串向量的任何一个元素的最佳方法