"C++ list insert"의 두 판 사이의 차이

9번째 줄: 9번째 줄:


int main(){
int main(){
string s;
string s = "hell";
cin >> s;


list<char> l(s.begin(), s.end());
list<char> l(s.begin(), s.end());
auto cursor = l.end();
auto cursor = l.end();


l.insert(cursor, "pp");  //에러 발생
l.insert(cursor, 'o');  //에러 발생


for (auto v : l){
for (auto v : l){
22번째 줄: 21번째 줄:
cout << '\n';
cout << '\n';
}
}
// hello
</source>
</source>



2018년 4월 11일 (수) 23:28 판

1 개요

C++ 커서의 위치에 문자 삽입

C++ list insert

#include <iostream>
#include <list>
#include <string>
using namespace std;

int main(){
	string s = "hell";

	list<char> l(s.begin(), s.end());
	auto cursor = l.end();

	l.insert(cursor, 'o');  //에러 발생

	for (auto v : l){
		cout << v;
	}
	cout << '\n';
}
// hello

2 같이 보기

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