例如,以下代码演示了如何在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