나는 txt 파일을 읽고 모든 행을 유형 문자열의 하나의 벡터로 반환해야하는 매우 간단한 함수를 사용했습니다. 필자는 디버거를 사용하여 여물을 밟았으며, 주목할 점은 ifstream 선언의 줄에서 "fileName"값이 변경된다는 것입니다. 내가 도대체 뭘 잘못하고있는 겁니까?? 고마워. //////////////////////////////////실행 중 C++ 인수가 변경되는 경우
vector<string> readFile(char* fileName)
{
vector<string> fileLines;
fileLines.clear();
string line;
ifstream myfile (fileName);
if (myfile.is_open())
{
while (myfile.good())
{
getline (myfile,line);
fileLines.push_back(line);
}
myfile.close();
}
return fileLines;
}
나는이 기능을 가질 수 현재 디렉토리의 모든 txt 파일의 파일 이름을 반환해야합니다. 함수가 호출 될 것입니다 방법
vector<char*> getFileList()
{
vector<char*> fileNames;
fileNames.clear();
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char currentPath[_MAX_PATH];
getCurrentPath(currentPath);
strncat(currentPath, "\\*", 3);
if (hFind = FindFirstFile(currentPath, &FindFileData))
{
string fileExtension = getExt(FindFileData.cFileName);
if (fileExtension == "txt" || fileExtension == "TXT")
{
fileNames.push_back(FindFileData.cFileName);
}
while(FindNextFile(hFind, &FindFileData) != 0)
{
string fileExtension = getExt(FindFileData.cFileName);
if (fileExtension == "txt" || fileExtension == "TXT")
fileNames.push_back(FindFileData.cFileName);
}
}
return fileNames;
}
:
vector<char*> inputFileList = getFileList();
if (inputFileList.size() > 0)
{
for (int a=0; a<inputFileList.size(); a++)
{
fileLines = readFile(inputFileList[a]);
}
}
최적화 기능을 사용하여 컴파일 중입니까? –
코드가 충분하지 않습니다. 함수 호출 호출 코드를 게시하는 것이 더 낫습니다. – karthik
최적화와 관련하여 어떤 의미입니까? 나는 Mingw와 함께 컴파일하고있다. Thx – Tom