C++ 문자열 at()

1 개요[ | ]

C++ .at()
#include <iostream>
using namespace std;
int main() {
	string s = "World";
	cout << s.at(0) << endl; // W
	cout << s.at(1) << endl; // o
	cout << s.at(2) << endl; // r
}
#include <iostream>
using namespace std;
int main() {
	string s = "World";
	cout << s[0] << endl; // W
	cout << s[1] << endl; // o
	cout << s[2] << endl; // r
}
#include <iostream>
using namespace std;
int main() {
	string s = "World";
	cout << s.at(3) << endl; // l
	cout << s.at(4) << endl; // d
	cout << s.at(5) << endl; // terminate called after throwing an instance of 'std::out_of_range'
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}