내가이 아직 완료되지 파일 리더/라이터 을 heres 코드를 작성 int로.유효하지 않은 변환은
#include <iostream>
#include <fstream>
#include <string>
const std::string path_to_data = "\\data";
const std::string level_file = path_to_data+"\\level_file.lev";
typedef std::string (*f_read)(std::ifstream& fin,const std::string& level_file,int line_num);
typedef std::string (*f_write)(std::ofstream& fout,const std::string& level_file, std::string& what_to_write,int line_num);
typedef std::string (*pt_f_manger)(f_read,f_write);
inline bool is_empty(std::ifstream& pFile){return pFile.peek() == std::ifstream::traits_type::eof();}
std::string file_manger(f_read,f_write);
std::string read_file(std::ifstream& fin,const std::string& level_file,int line_num);
std::string write_file(std::ofstream& fout,const std::string& level_file,std::string what_to_write, int line_num);
std::string error_handler(std::string error_type,pt_f_manger f_manger);
int main()
{
std::string error = file_manger(read_file,write_file);
std::cout<<error<<"\n";
std::cin.get();
std::cin.get();
return 0;
}
std::string file_manger(f_read f_input,f_write f_output)
{
std::string good = "good";
std::string error = "error";
std::ifstream fin;
std::ofstream fout;
std::string test = "test";
std::string output = f_output(fout,level_file,test,0);
std::string input = f_input(fin,level_file,0);
if (output != "good")
return error;
if (input != "good")
return error;
return good;
}
std::string write_file(std::ofstream& fout,const std::string& level_file, std::string& what_to_write,int line_num)
{
const char* level_filec = level_file.c_str();
std::ifstream fin;
fin.open(level_filec);
if (fin.is_open())
return "failed to open "+level_file;
if (is_empty(fin))
{
fin.close();
fout.open(level_filec);
if (!fout.is_open())
return "failed to open "+level_file;
fout<<what_to_write;
fout.close();
return "good";
}
int i = 0;
int num = 0;
char ch;
while (fin.good() && i != line_num)
{
fin.get(ch);
if (ch == '\n')
++num;
++i;
}
int pos = fin.tellg();
fin.close();
fout.open(level_filec,std::ios_base::in);
if (!fout.is_open())
return "failed to open "+level_file;
fout.seekp(pos);
fout<<what_to_write;
fout.close();
return "good";
}
std::string read_file(std::ifstream& fin,const std::string& level_file,int line_num)
{
const char* level_filec = level_file.c_str();
std::string read;
fin.open(level_filec);
if (fin.is_open())
return "failed to open "+level_file;
if (is_empty(fin))
{
fin.close();
return "file is empty";
}
int i = 0;
int num = 0;
char ch;
while (fin.good() && i != line_num)
{
fin.get(ch);
if (ch == '\n')
++num;
++i;
}
std::getline(fin,read);
return read;
}
std::string error_handler(std::string error_type,pt_f_manger f_manger)//work in progress
{
return "good";
}
와 나는
C이 오류 : 'INT 주()'기능으로 사용자 \ 존 \ 문서 \ MAIN.CPP || \ : | C : \ 사용자 \ 존 \ 문서 \ MAIN.CPP | 25 | 오류 : 'std :: string (*) (std :: basic_ststream (std :: basic_ofstream)에서 std :: ofstream &, const 문자열 &, std :: string, int) const std :: basic_string &, const std :: basic_string &, std :: basic_string &,, const std :: basic_string &, std :: basic_string, int) int)} '[-fpermissive] | C : \ Users \ john \ Documents \ main.cpp | 17 | error : 'std :: string file_manger (f_read, f_write)'의 인수 2 초기화 중 [-fpermissive] | || === 빌드 완료 : 2 개 오류, 0 개 경고 (0 분, 0 초) === |
메신저는 code :: blocks을 사용합니다.
신원을 확인하십시오. – Borgleader