원본 자체의 C++ 프로그램 인쇄

사고방식: 먼저 틀을 잘 써라.프레임을 문자열로 변환합니다.
따옴표, 줄 바꿈 처리: 이 두 문자는 일반적으로 문자열에서 뜻을 바꾸기 때문에 바꿀 때 직접 쓸 수 없고 ASCII 값으로 표시해야 한다.
#include <iostream>
using namespace std;

string replace_all(string src, char tc, string const & w)
{
  string s(src);
  string t(1, tc);
  unsigned int pos = s.find(t), t_size = t.size(), r_size = w.size();
  while(pos != std::string::npos){
    s.replace(pos, t_size, w);
    pos = s.find(t, pos + r_size );
  }
  return s;
}

int main()
{
  char const *s = "#include <iostream>
using namespace std;

string replace_all(string src, char tc, string const & w)
{
string s(src);
string t(1, tc);
unsigned int pos = s.find(t), t_size = t.size(), r_size = w.size();
while(pos != std::string::npos){
s.replace(pos, t_size, w);
pos = s.find(t, pos + r_size );
}
return s;
}

int main()
{
char const *s = |@|;
char const q[] = {34,0};
char const n[] = {92,110,0};
cout << replace_all(replace_all(s,124,q), 64, replace_all(s, 10, n));
}
"; char const q[] = {34,0}; char const n[] = {92,110,0}; cout << replace_all(replace_all(s,124,q), 64, replace_all(s, 10, n)); }

좋은 웹페이지 즐겨찾기