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


#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();
}