#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
void A() {
string file("test.txt.zip");
FILE* fout = fopen(file.c_str(), "w");
size_t pos = file.rfind('.');
if (pos != string::npos)//npos=-1的意思{
//string suf = file.substr(pos, file.size() - pos);
string suf = file.substr(pos);
cout << suf << endl;
}
};
void B() {
A();
}
int main() {
B();
return 0;
}
string 找find
这段代码展示了在C++中如何使用fopen函数打开并写入文件,同时提取文件名的扩展名。通过对字符串的rfind和substr方法的运用,可以方便地获取文件扩展名。

被折叠的 条评论
为什么被折叠?



