C++ 如何使用filepath进行函数调用?
我只想调用文件路径为“/home/merve/merve.txt”的函数:C++ 如何使用filepath进行函数调用?,c++,linux,file,function,filepath,C++,Linux,File,Function,Filepath,我只想调用文件路径为“/home/merve/merve.txt”的函数: void GenerateUnecryptedData(const char*pathToUnencryptedFile) { //文件结构: 整数偏移=0; 流文件; myfile.open(“pathToUnencryptedFile”,ios::out | ios::app | ios::binary); //+20字节任意选择的数据(偏移量:0) myfile.seekp(offset)只需将其作为变量传入。如果
void GenerateUnecryptedData(const char*pathToUnencryptedFile)
{
//文件结构:
整数偏移=0;
流文件;
myfile.open(“pathToUnencryptedFile”,ios::out | ios::app | ios::binary);
//+20字节任意选择的数据(偏移量:0)
myfile.seekp(offset)只需将其作为变量传入。如果在其周围加引号,它将被解释为string
literal。此外,我建议使用std::string
而不是char*
void GenerateUnecryptedData(std::string const pathToUnencryptedFile)
{
ofstream myFile{pathToUnencryptedFile, ios::out | ios::app | ios::binary};
}
那你就称它为
GenerateUnecryptedData("/home/merve/merve.txt");
myfile.open(“pathToUnencryptedFile”
…您可能想将参数变量传递给open
,而不是包含变量名称的字符串文字。请丢失引号。
GenerateUnecryptedData("/home/merve/merve.txt");