Stringreplace 함수를 사용하세요.
뉴비 님이 쓰신 글 :
:
:
: 1 #include<iostream>
: 2 #include<string>
: 3 #include<fstream>
: 4 #include<algorithm>
: 5 #include<time.h>
: 6 using namespace std;
: 7
: 8 string replace(string s)
: 9 {
: 10 replace(s.begin(),s.end(),0,0);
: 11 return s;
: 12 }
: 13
: 14 int main()
: 15 {
: 16 string* sp;
: 17 int x;
: 18
: 19
: 20 ifstream inf("stage3.txt");
: 21 ofstream outf("Decrypted.txt");
: 22 inf >> x;
: 23 inf.ignore();
: 24 sp=new string[x];
: 25 time_t rawtime;
: 26 struct tm* timeinfo;
: 27 time(&rawtime);
: 28 timeinfo=localtime(&rawtime);
: 29
: 30 for(int i=0; i<x; ++i)
: 31 {
: 32 string s;
: 33 getline(inf,s);
: 34 sp[i]=replace(s);
: 35
: 36 if(sp[i].find("Decrypt stage 1 complete")!=string::npos)
: 37 sp[i]="Decrypted by Y";
: 38 if(sp[i].find("Decrypt stage 2 complete")!=string::npos)
: 39 sp[i]=asctime(timeinfo);
: 40
: 41 cout<< sp[i] <<endl;
: 42 }
: 43
: 44 for(int i=0; i<x; ++i)
: 45 {
: 46 outf<< sp[i]<<endl;
: 47 }
: 48 sp=NULL;
: 49 delete []sp;
: 50 }
: 대충 소스는 짜봤는데요,
: Replace “barn” with “Galactica”
:
: Replace “toaster” with “Cylon”
:
: Replace “juice” with “fuel”
:
: Replace “wagon” with “viper”
:
: Replace “stage 1” with the current time
:
: Replace “stage 2” with “FRAKKEN”
: 각각 이 단어들을 replace해야 하는데 어떻게 하는지 모르겠어요
: 루프안에다가 if 로 쓰니까 문장 전체가 교체되버려서 하나씩만 교체 하려면 어떻게 하는지 모르겠어요 도와주세요 ㅠ
:
: