c++ define 报错
伊谢尔伦
伊谢尔伦 2017-04-17 11:07:36
0
3
637
#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 为什么会报错?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
Peter_Zhu

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.

PHPzhong

Because NEWAPPPATH is a C string, and of course C string does not have the substr method.

黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template