问题: 如何从数组字符串中提取字符?
解释: 普通字符串
string example=("Stack Over Flow");
cout<<example[1];
输出将是:
t
我想要的是从字符串数组中提取一个字母示例:
string str[4];
str[0]="1st";
str[1]="2nd";
str[2]="3rd";
str[3]="4th";
cout<<str[2];
将打印
3rd
我如何从 str[0]
中获取“t”?
最佳答案
只需按照以下步骤操作即可:
str[0][2]; // third character of first string
更多例子:
string str[4];
str[0]="1st";
str[1]="2nd";
str[2]="3rd";
str[3]="4th";
cout<<str[0][2]<<endl; // t
cout<<str[2][1]<<endl; // r
cout<<str[3][2]<<endl; // h
关于C++ 读取字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340650/