C : B를 사용하여 7 번 창에서 C++로 작성한 프로그램에 문제가 있습니다. 다음은 파일의 행 수를 확인하기 위해 사용하고있는 코드입니다. 첫 번째 부분은 gotoline 함수의 선언이고, 그 다음에 파일의 행 수를 계산하는 코드 부분이옵니다. 로깅 프로세스를 추가하기 전까지는 아무 문제가 없었습니다. 어쩌면 정보를 잘못 로깅하거나 단일 함수 내에서 너무 많은 파일을 열고 닫는 작업을하고 있습니까? 제 실수를 밝히는 데 큰 도움이 될 것입니다. 제 문제에 대해 더 자세히 설명해 주시면 기꺼이 부탁드립니다. 나는 아직도 C++을 배우고 있는데, 왜 내 프로그램이 라인 계산을 멈추게되었는지 혼란 스럽다.내 파일에 대한 세부 정보를 기록한 이후로 어떤 일이 발생 했습니까?
std::ifstream& GotoLine(std::ifstream& file, unsigned int num)
{
file.seekg(std::ios::beg);
for(int i=0; i < num - 1; ++i)
{
file.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
return file;
}
ifstream productguide;
productguide.open ("MasterProductGuide.csv");
if (productguide.good())
{
c = productguide.get();
if (c=='\n')x++;
ofstream log;
log.open ("log.txt", ofstream::app);
if (log.good())
{
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
string loginfo;
loginfo = asctime (timeinfo);
log << "MarketManager Detected " << x << " # of lines in the Master Product Guide - " + loginfo;
}
else
{
cout << "There was an error creating the log file" << endl;
cout << "The Program will now terminate" << endl;
system("PAUSE");
return 0;
}
log.close();
}
else
{
ofstream log;
log.open ("log.txt", ofstream::app);
if (log.good())
{
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
string loginfo;
loginfo = asctime (timeinfo);
log << "MarketManager Failed to oped the Master Product Guide - " + loginfo;
}
else
{
cout << "There was an error creating the log file" << endl;
cout << "The Program will now terminate" << endl;
system("PAUSE");
return 0;
}
log.close();
cout << "The Program will now terminate" << endl;
system("PAUSE");
return 0;
}
productguide.close();
내가 아무것도 이해하지 반환해야합니다. 이 소스 파일의 정식 버전을 게시 할 수 있습니까? –
가독성을 위해 문제를 해결하는 방법 때문에 거의 1000 줄이 있습니다. 게시하지 않고 전송하는 더 좋은 방법이 있습니까? – Rob
이 두 가지 코드는 나에게 잘 보입니다. 그래서 문제는 다른 장소에 있다고 생각합니다. –