我想檢查的目錄只是從Microsoft Visual C++標準項目文件夾默認情況下寫入/讀取文件如果用戶輸入一個字符串到C++中,我該如何檢查該目錄中是否有該文件中的文件以及它的擴展名是什麼?
下面是我已經,它提示用戶輸入文件名。最終我希望能夠通過套接字發送此文件,但目前我只是想查看該文件名的目錄,然後將其擴展名添加到發送。
printf("Please enter the name of the file you wish to send.\n\n");
string inputFile;
std::cin >> inputFile;
/*ofstream myfile;
myfile.open("example.txt");
myfile << "Writing this to a file.\n";
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (getline (myfile,line))
{
cout << line << '\n';
}
myfile.close();
}
myfile.close();
*/
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
/*ifstream my_file(inputFile+".*");
if (my_file.good())
{
printf("Success");
}*/
}
/*
if (inputFile == "example")
{
inputFile = example.txt;
AESFileEncrypt(inputFile.c_str(), HKab);
AESFileDecrypt(HKab);
string STRING;
ifstream infile;
infile.open("example_aes.txt");
int a=0;
string previousLine="";
while(a<1) // To get you all the lines.
{
getline(infile,STRING); // Saves the line in STRING.
if (STRING != previousLine)
{
previousLine=STRING;
cout<<STRING<<endl; // Prints our STRING.
}
infile.close();
system ("pause");
}
//connectedSocket->SendFile("AES"+inputFile);
}
else if (inputFile == "liverpool")
{
inputFile = liverpool.jpg;
AESFileEncrypt(inputFile.c_str(), HKab);
AESFileDecrypt(HKab);
}
}
else
{
printf("You have not selected a valid option.\n\n");
}
*/
}
http://stackoverflow.com/questions/3828835/how-can-我們檢查是否存在或不使用win32程序 –
最好從代碼中移除註釋以使其更清晰。 – Nejat