开发者

How to represent spaces in visual c++?

How to represent the space inside this statement:

C:\\Program Files

so that I can put it inside my code properly. I suspect that my program does not work, because of the 'missing' char :(

I want to declare like this:

static char Log[256] = "C:\\Program Files\\Mywork\\text.txt";

This one does not work too:

      SHELLEXECUTEINFO info = {0};
  info.cbS开发者_JAVA百科ize = sizeof(SHELLEXECUTEINFO);
  info.fMask  = SEE_MASK_NOCLOSEPROCESS;
  info.lpFile = _T("C:\\Program Files\\Mywork\\iecapt.exe");

I am currently using visual studio to compile this. It can compile, but when running, it give error could not find the iecapt.exe.


The problem is not the space, it is the backslashes. Try this:

static char Log[256] = "C:\\Program Files\\Mywork\\text.txt";

Otherwise the backslashes mean "interpret the next character according to the C string escaping rules, where "\t" for example means TAB.

The @"literal string" syntax suggested in another answer might work too, but I don't think it's standard outside of Windows.


@"my string here"

@ signifies a 'verbatim' string

should work!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜