#include <iostream>
#include <string>
using namespace std;
int main()
{
#define NEW_APP_PATH "C:\\QQ\\QQ.exe";
#define VAL_OPEN NEW_APP_PATH.substr(0,NEW_APP_PATH.find_last_of('\\'));
cout<<VAL_OPEN;
getchar();
return 0;
}
用define 为什么会报错?
天蓬老师2017-04-17 11:09:36
NEWAPPPATH.substr NEWAPPPATH is a char[] array and does not support . operation; it can be modified to NEWAPPPATH string("C :QQQQ.exe") give it a try.
PHPz2017-04-17 11:09:36
Because NEWAPPPATH is a C string, and of course C string does not have the substr method.
黄舟2017-04-17 11:09:36
The whole program is wrong, not just the define problem
C ’s native strings have no member functions
There is no semicolon at the end of the macro definition
#define NEWAPPPATH std::string("C:QQQQ.exe")
#define VALOPEN NEWAPPPATH.substr(0,NEWAPPPATH.findlast_of(''))
This allows the compiler to reluctantly execute