그래서 파일에서 문자를 읽고 문자 배열에 저장 한 다음 새로운 파일. 단, 모든 문자의 원시 숫자가 하나씩 증가합니다 (대부분의 숙련 된 프로그래머는 여기서 내가 아는 내용을 알게됩니다). 그래서 기본적으로 내 자신의 암호화 알고리즘을 만들려고합니다. 그러나 나는 매우 이상한 오류가 발생합니다 : <various paths here>\main.cpp|27|error: no match for 'operator<<' (operand types are 'std::ifstream {aka std::basic_ifstream<char>}' and 'char')|
이 오류에 대해 많이 들었습니다.하지만 사람들이 클래스 정의 함수를 사용할 때만 발생합니다. 프로그램에서하지 않은 것입니다. 이 오류가 나는 사람들이 찾을 수있는 생각 메모와 함께 그것을 유용하게 저를 도와 :fstream을 사용하여 파일에 문자 쓰기 시도 : 'operator <<'와 일치하지 않음
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int array_size = 1024000;
char Str[array_size];
int position = 0;
long double fsize = position;
ifstream finput("in.txt");
ifstream foutput("out.txt");
if(finput.is_open()) {
cout << "File Opened successfully. Storing file data into array." << endl;
while(!finput.eof() && position < array_size) {
finput.get(Str[position]);
position++;
fsize = position;
cout << "Processed data: " << fsize/1000 << "KB" << endl;
}
Str[position-1] = '\0';
cout << "Storing done, encoding..." << endl << endl;
for(int i = 0; Str[i] != '\0'; i++) {
cout << Str[i] << "changed to " << char(Str[i] + 1) << endl;
foutput << Str[i] += 1;
}
} else {
cout << "File could not be opened. File must be named in.txt and must not be in use by another program." << endl;
}
return 0;
}
주 : I 출력 문자열에 fstream를 사용하고있다 (안 <various paths here>\main.cpp|27|note: no known conversion for argument 1 from 'std::ifstream {aka std::basic_ifstream<char>}' to 'int'|
소스 코드는 다음과 같다 문자들, 이것을 염두에 두라.) 다른 시간에 파일에, 그리고 그것은 잘 작동했다! 대신 ofstream foutput
의 ifstream foutput
을 선언 한