我试图从用户输入中获取一个目录并将其存储在boost库中的路径对象中。当目录中没有空格时,这可以很好地工作,例如C:\ Windows \ system32 \ file.exe但是当试图使用C:\ Program Files \ file.exe时,它不起作用,程序刚刚退出。我正在考虑将输入作为字符串,然后对其进行操作以用换码符替换空格。有一个更好的方法吗?如何处理boost :: filesystem :: path的空格
boost::filesystem::path path;
std::cout << "Please enter the path for the file you would like to hash:" << std::endl;
std::cout << "E.g. C:\\Program Files\\iTunes\\iTunes.exe" << std::endl;
std::cin >> path;
该路径然后传递给函数进行散列。对于没有空格的路径工作良好,但是程序刚好退出。
std::string md5_file(boost::filesystem::path &file)
{
/* Takes a file and returns the md5 hash. */
// Create new hash wrapper
hashwrapper *myWrapper = new md5wrapper();
std::string hash;
// Hash file
try
{
hash = myWrapper->getHashFromFile(file.string());
}
catch (hlException &e)
{
std::cerr << "Error(" << e.error_number() << "): " << e.error_message() << std::endl;
}
// Clean up
delete myWrapper;
return hash;
}
更具体究竟是什么休息时间。 'filesystem :: path'没有处理空格的问题。 – Pavel
你最小的可编译示例在哪里,什么是“一切都打破了?”这是否包括显示器着火或整个区块停电? –
尝试使用'getline'获取用户提供的整个行 – AndyG