줄 짜기 기능을 클래스로 옮기려고하는데, 몇 가지 오류가 발생했습니다. 어떻게 작동하는지 모릅니다.C++ 클래스를 사용하여 파일의 줄 수를 계산합니다.
class lines {
string name;
int number_of_lines;
string line;
public:
void set_value (string n);
ifstream myfile(name); //C2061: syntax error : identifier 'name'
while (getline(myfile, line)) //Multiple markers at this line - C2059: syntax error : 'while', - Syntax error
{ // C2334: unexpected token(s) preceding '{'; skipping apparent function body
++number_of_lines;
}
int row() {return number_of_lines;}
};
void lines::set_value (string n) {
number_of_lines=0;
name = n;
}
표시되는 행에 주석을 추가했습니다.
. 먼저 함수 선언에서 유형이 아닌 변수 이름을 사용하고 있습니다. 둘째, 멤버 함수를 선언하고 클래스 정의에서 멤버 함수 정의로 사용하려는 코드 블록을 수행합니다. – Bandrami
간단하게하십시오. 버퍼 된 입력을 사용하여 바이트 단위로 2 바이트 버퍼로 읽고 CR/LF/CRLF 시퀀스를 확인하십시오. – Dariusz