C++ 中的 string at() 函式\n
在本節中,我們將瞭解 C++ 中的 at() 函式。at() 函式用於訪問指定位置的字元。
在此程式中,我們將使用 at() 遍歷每個字元,並將它們列印到不同的行中。
示例程式碼
#include<iostream>
using namespace std;
main() {
string my_str = "Hello World";
for(int i = 0; i<my_str.length(); i++) {
cout << my_str.at(i) << endl; //get character at position i
}
}輸出
H e l l o W o r l d
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP