질문의 주제가 정확하지는 않지만 여기에 문제가 있습니다. 나는 사람이 자신의 텍스트를 쓰는 파일을 가지고있다. 예를 들어 '오늘은 아주 좋은 날'이고 txt 문서에 저장한다. 그리고 나서이 모든 charaters를 가져 와서 한 문자 더 이동하십시오 (a는 b가되고 z는 a가됩니다). 그러나 나는 그 장소에 공간을 두어야한다.배열에 공간을 추가하는 방법
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
string a;
string Code;
string New;
ifstream File ("Txt.txt");
File>>Code;
for (int i = 0; i<Code.size(); i++){
if (Code.at(i) >= 'A' && Code.at(i) <= 'V' || Code.at(i) >= 'a' && Code.at(i) <= 'v') {
a = Code.at(i) + 4;
New += a;
}
else if (Code.at(i) == 'W'){
a = 'A';
New += a;}
else if (Code.at(i) == 'X'){
a = 'B';
New += a;}
else if (Code.at(i) == 'Y'){
a = 'C';
New += a;}
else if (Code.at(i) == 'Z'){
a = 'D';
New += a;}
else if (Code.at(i) == 'w'){
a = 'a';
New += a;}
else if (Code.at(i) == 'x'){
a = 'b';
New += a;}
else if (Code.at(i) == 'y'){
a = 'c';
New += a;}
else if (Code.at(i) == 'z'){
a = 'd';
New += a;}
else if (Code.at(i) == ' '){
a = Code.at(i);
New += a;
}
}cout<<New;
return 0;
}
그러나 프로그램은 첫 번째 단어 만 읽습니다. 모든 공백으로 모든 텍스트를 읽도록 프로그램을 어떻게 변경해야합니까?
이'문을 if' (26 + 1) mod 26 = 1이며 'a'는 첫 번째 문자입니다. – PaulMcKenzie
이 질문에 대한 답변 : http://stackoverflow.com/questions/37449872/how-to-read-in-multiple-words-from-a-text-file –