温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

c/c++ 强制去掉转移字符的办法 以及 仿函数

发布时间:2020-06-26 14:32:39 来源:网络 阅读:1595 作者:超级极客 栏目:编程语言


#include<iostream>
#include<functional>

using namespace std;
using namespace std::placeholders;


//去掉转移字符的方法
void main()
{
 //比如我门要打开qq
 //第一种
 string str = "C:\Program Files\QQ\Bin\QQ.exe";
 system(str.c_str());
 //有转移字符的存在是不是很蛋疼呢
 //接下来我们强制去掉转义字符
 //R"()"  可以强制去掉括号的转移字符  是不是很爽
 string str2 =R"( "C:\Program Files\QQ\Bin\QQ.exe")";
 system(str2.c_str());

 cin.get();
}

struct MyStruct
{
 void add(int a)
 {
  cout << a << endl;
 }
 void add2(int a, int b)
 {
  cout << a + b << endl;
 }
 void add3(int a, int b,int c)
 {
  cout << a + b+c << endl;
 }


};
//这个是 仿函数
void main23()
{
 MyStruct  struct1;
 auto func = bind(&MyStruct::add, &struct1,_1); //函数指针 直接用别人的成员函数
 //参数  加实例化  加 参数个数  即可绑定
 func(100); //fun是函数指针

 auto func2 = bind(&MyStruct::add2, &struct1, _1,_2);//表示占位
 func2(100, 20);

 auto func3 = bind(&MyStruct::add3, &struct1, _1, _2, _3);
 func3(10, 20, 50);
 //void(MyStruct*p)(int a) = &MyStruct::add;
 cin.get();
}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI