/*!
* @brief 返回文件中第n行,字符串sign之前的字符串
* @param [in] const std::string * filepath 文件路径
* @param [in] const size_t n 第n行
* @param [in] const std::string sign 字符串标识
* @return bool
*/
std::string GetLineBeginSign(const std::string filepath, const size_t n, const std::string sign);
/*!
* @brief 删除文件
* @param [in] const std::string filepath 文件路径
* @return bool
*/
bool DeleteFile(const std::string filepath);
std::string CTestHelper::GetLineBeginSign(const std::string filepath, const size_t n, const std::string sign)
{
ifstream inFile(filepath);
std::string line, str;
if (inFile)
{
// 找到第n行
int i = 0;
while(i < n)
{
if( !getline(inFile, line))
cout<<"file "<<filepath<<" does not have "<<i + 1<<" lines"<<endl;
i ++;
}
// 找到sign的位置
size_t pos = line.find_first_of(sign);
if(pos == string::npos)
cout<<"file "<<filepath<<" "<<i + 1<<" line does not have "<<sign<<endl;
str = line.substr(0, pos);
}
return str;
}
bool CTestHelper::DeleteFile(const std::string filepath)
{
if (-1 == remove(filepath.c_str()))
{
return false;
}
return true;
}
// 删除文件
string delFile = (string)"del" + " " + simplydMeshPath;
system(delFile.data());
文件的操作:读取某一行开头,删除文件
最新推荐文章于 2021-05-23 01:03:24 发布