加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C++中图片重命名实现代码

发布时间:2020-12-16 05:10:12 所属栏目:百科 来源:网络整理
导读:非常简单的小程序,满足自己的需求。 #include iostream#include fstream#includesstreamusing namespace std; int main(){ int i=1,j=1; //本人程序中,i 和 j 是介于(0-9之间的数字),为了简单起见,这里给定初始值。 string fname1= "C:UsersAdmini

非常简单的小程序,满足自己的需求。

#include <iostream>
#include <fstream>
#include<sstream>
using namespace std;
 
int main()
{
  int i=1,j=1;   //本人程序中,i 和 j 是介于(0-9之间的数字),为了简单起见,这里给定初始值。
  string fname1= "C:UsersAdministratorDesktop121.bmp";  //源文件
  string fname2 = "C:UsersAdministratorDesktop";
 
  ostringstream oss;
  oss<<i<<j<<".bmp";
  fname2 += oss.str(); //将int型变量和string变量相加在一起
  //cout<<fname2<<endl;
 
  fstream f;
  f.open(fname1.c_str());
  if(!f)
  {
    cout<<"图片不存在!"<<endl;
  }
  else
  {
    
    rename(fname1.c_str(),fname2.c_str());
    cout<<"成功将重命名为"<<endl;
 
    f.close();
  }
 
  return 0;
 
}

文章到此结束,需要的朋友可可以参考一下。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读