안녕하세요 엘체프 GG 임돠
C 문자열을 바꾸는 소스 올립니다.
문) "C언어는 객체지향 언어이다." 라는 말을 지역변수로 입력받아서
"C언어는 구조적 언어이다."로 변경하는 프로그램을 작성하십시오.
-답
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
#include <iostream>
#include <string>
using namespace std;
void main() {
// string str("C언어는 객체지향 언어이다.");
string str = "C언어는 객체지향 언어이다.";
string oriWord = "객체지향";
string repWord = "구조적";
size_t found = str.find(oriWord);
while (found != string::npos) {
str.replace(found, oriWord.length(), repWord);
found = str.find(repWord, found + 1);
}
cout << str << endl;
system("PAUSE");
} |
cs |
감사합니다.
'스터디 > C,C++' 카테고리의 다른 글
C++ map을 이용한 login 문제 (6) | 2018.02.28 |
---|---|
C 문자열(string) 분리 (6) | 2018.02.28 |
마지막 C 시험문제 공백 사각찍기 (7) | 2018.02.28 |
C++ 문자열 경사면 인쇄하기 (9) | 2018.02.19 |
C++ 클래스 실습과제 (7) | 2018.02.19 |