例如,以下代码演示了如何在QT中使用strstr函数:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str1[] = "hello world";
char str2[] = "world";
char *ptr = strstr(str1, str2);
if (ptr != NULL)
{
cout << "Found at position " << ptr - str1 << endl;
}
else
{
cout << "Not found" << endl;
}
return 0;
}
输出结果为:
Found at position 6
本文展示了在C++QT环境中如何使用strstr函数进行字符串搜索,通过给定helloworld和world的例子,演示了函数的用法及其输出结果。
673

被折叠的 条评论
为什么被折叠?



