How to add/insert char in front of string in c++, 스트링 문자 앞에 char문자 캐릭터 추가하는 방법, 예제, example code, java
There are many things how to append char on string
string 에 char 를 덧붙이는 방법은 여러가지가 있다.
- using + operator
- using push_back function
- using append function
- using insert function
- using resize function
But, if you wanna add char to the location you want to, then use insert
e.g. on the beginning of the string
- 오퍼래이터 += 를 이용
- push_back 함수를 이용
- append 함수를 이용
- insert 함수를 이용
- resize 함수를 이용
그 중 맨 뒤가 아닌 원하는 위치에 껴넣으려면 insert 함수를 쓰는게 편했다.
e.g. 맨 앞에
Code.. lemme see code...
코드.. 코드를 보자...
e.g.
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
char character = 'c';
string stringBuffer("testString");
// Append to the end of string
stringBuffer += character;
cout << stringBuffer << endl;
stringBuffer.push_back(character);
cout << stringBuffer << endl;
stringBuffer.append(1, character);
cout << stringBuffer << endl;
stringBuffer.insert(stringBuffer.end(), 1, character);
cout << stringBuffer << endl;
stringBuffer.resize(stringBuffer.size() + 1, character);
cout << stringBuffer << endl;
stringBuffer += string(1, character);
cout << stringBuffer << endl;
// Append to the front of string
stringBuffer.insert(stringBuffer.begin(), character);
cout << stringBuffer << endl;
}
Something else you might like...?
2019/02/12 - [Programming/C++] - How to use map in c++ STL, c++ 맵 STL 사용방법/초기화/예제, java, example, sample, library, find, insert, first
2019/02/04 - [Programming/C++] - How to add DLL / external lib file to VisualStudio, 비주얼스튜디오 외부라이브러리 dll 파일 추가 방법, example, c++ java api
2019/01/31 - [Programming/Java] - How to convert Decimal to Hexa, 10진수 숫자 16진수 숫자로 변환/바꾸기, Java c++, example, code
2019/01/30 - [Programming/Software Architecture] - What is Object Oriented Design/Artchitecture? 객체지향 디자인/설계란? java,c++,softwareArchitecture,designPattern
2019/01/29 - [Programming/Programming Language] - 클린코딩/더 나은 코딩을 하는 10가지 방법, 10 Tips for clean code/ better code/ quality code.
2019/01/22 - [Programming/Java] - How to make Date format in Java, 자바 SimpleDateFormat 연월일/날짜 형식, time, 시분초
2019/01/15 - [Programming/Java] - How to use RxTx libraries, error/bug. RxTx Serial 통신 라이브러리 사용 방법,에러,버그 / Java
2019/01/16 - [Computer/General] - Path/Location of temporary files in each OS, 운영체제별 임시파일 저장 경로/위치
2018/12/28 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 - (#9, Tell, Don't Ask)
2018/12/26 - [Programming/Software Architecture] - Perfecting OO's Small Classes and Short Methods. 완벽한 객체지향의 작은 클래스와 짧은 메소드, Book:ThoughtWorks Anthology, Java,cpp,자바,oop,좋은코드,객체지향프로그래밍 (1)
2019/01/16 - [Algorithm/Leet Code] - LeetCode #217 ContainsDuplicate. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접
2019/01/21 - [Algorithm/Leet Code] - LeetCode #219 ContainsDuplicate2. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접
2019/01/22 - [Algorithm/Leet Code] - LeetCode #220 ContainsDuplicate3. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,기술면접
2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #60 sudoku. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive
2019/01/12 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #59 spiralNumbers. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive
2019/01/08 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #58 messageFromBinaryCode. Algorithm,알고리즘,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive
2019/01/25 - [Life/Health care] - Maca 마카 usage/side effects/dosage 효능/부작용/성인,소아 용법(2)
2019/01/25 - [Life/Health care] - L-Arginine 아르기닌 usage/side effects/dosage 효능/부작용/성인,소아 용법(3)
2019/01/28 - [Life/Health care] - Rogaine 로게인(Minoxidil, 미녹시딜, 마이녹실) usage/sideEffects/dosage 효능/부작용/사용법