假设我有一个分配给字符串变量的文本文件“myfile.txt”,我想删除点和扩展文件字符的其余部分.txt
#include <stdio.h>
#include <string>
#incldue <iostream>
int main() {
std::string F = "myfile.txt";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以我想要实现的输出是“myfile”。使用 std::size 看起来并不适用于我的情况,有没有办法可以构建我想要的东西?
我需要根据用户的输入从目录中删除文件并将其传递到执行文件删除程序过程的函数中
/* Class 3 veus 3:45PM*/
#include <string>
#include <iostream>
#include <stdio.h>
#include <cstdio>
void remove_file(std::string file);
int main() {
std::string file_name;
std::cin >> file_name;
remove_file(file_name);
}
void remove_file(std::string file) {
if(remove("C:\\MAIN_LOC\\" + file + ".txt") == 0) {
std::cout << "`" << file << "`" << " Item deleted successfully" << std::endl;
} else {
std::cout << "[Error] File not found";
}
}
Run Code Online (Sandbox Code Playgroud)
好吧,现在的问题是我在remove函数上遇到了几个错误:function "remove" cannot be called with the given argument list。我不确定这个错误是什么意思,所以我想得到解释。
c++ ×2