문제

메인이라는 프로그램이 있습니다.

#include<iostream>
#include<fstream>
using namespace std;
#include"other.h"
int main()
{
//do stuff
}

그리고 기타 .H :

char* load_data(int begin_point,int num_characters)
{
    seekg(begin_point);
    char* return_val=new char[num_characters+1];
    mapdata.getline(return_val,num_characters);
    return return_val;
}

그리고 오류가 발생합니다.

'Seekg': 식별자를 찾을 수 없습니다

왜이 오류가 발생하고 어떻게 수정합니까?

도움이 되었습니까?

해결책

Seekg는 FStream (Istream으로 선언 된) 클래스의 방법입니다.

당신은 인스턴스화하지 않았습니다.

이것을 예로 들어보십시오

  ifstream is;
  is.open ("test.txt", ios::binary );

  // get length of file:
  is.seekg (0, ios::end);

원천: http://www.cplusplus.com/reference/iostream/istream/seekg/

그래서 당신은해야합니다

char* load_data(int begin_point,int num_characters)
{
    ifstream is;
    is("yourfile.txt") //file is now open for reading. 

    seekg(begin_point);
    char* return_val=new char[num_characters+1];
    mapdata.getline(return_val,num_characters);
    return return_val;
}

Paroxon이 귀하의 질문에 대해 언급 한 내용을 고려하십시오.

function의 load_data 구현을 포함하는 파일 Other.cpp를 만들어야합니다. 파일 Other.h에는 function의 load_data 선언이 포함되어야합니다. 해당 파일 (Other.h)에는 작동하도록 선언 된 기능에 대한 모든 파일을 포함해야합니다. 그리고 여러 포함 된 포함로 자신을 보호하는 것을 잊지 마십시오!

기타를 제출하십시오 .h

#ifndef __OTHER_H__
#define  __OTHER_H__

#include <iostream>
#include <fstream>

char* load_data(int,int);//no implementation
#endif

기타 .cpp를 제출하십시오

#include "other.h" //assumes other.h and other.cpp in same directory

char* load_data(int begin,int amount){
      //load_data implementation
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top