本文共 1204 字,大约阅读时间需要 4 分钟。
c ++查找字符串
Program 1:
程序1:
#includeusing namespace std;int main(){ char* STR[] = { "HELLO", "HIII", "RAM", "SHYAM", "MOHAN" }; cout << (*STR + 2)[2]; return 0;}
Output:
输出:
O
Explanation:
说明:
Here we create an array of pointers to store strings. Now, look at the cout statement,
在这里,我们创建一个指针数组来存储字符串。 现在,看看cout语句,
cout<<(*STR+2)[2];
The above statement will print the element of the 4th index of 1st string because pointer STR pointing the 1st string that is "HELLO" so the above statement will print 'O'.
上面的语句将打印第一个字符串的第4 个索引的元素,因为指针STR指向“ HELLO”的 第一个字符串,因此,上面的语句将打印“ O” 。
Program 2:
程式2:
#includeusing namespace std;int main(){ char STR[5][8] = { "HELLO", "HIII", "RAM", "SHYAM", "MOHAN" }; cout << STR[2] + 1; return 0;}
Output:
输出:
AM
Explanation:
说明:
Here, we created a program two-dimensional array for strings. Now look the cout statement,
在这里,我们为字符串创建了一个程序二维数组。 现在看一下cout语句,
cout<
In the above statement, STR[2] is pointing to the 'R' in the string "RAM" and we move pointer one position ahead then it will print "AM" on the console screen.
在上面的语句中, STR [2]指向字符串“ RAM”中的“ R ” ,我们将指针向前移动一个位置,然后它将在控制台屏幕上打印“ AM” 。
Recommended posts
推荐的帖子
翻译自:
c ++查找字符串
转载地址:http://crxzd.baihongyu.com/