0

I am reading a directory from a file, for example I loaded this "Main\Characters\Player.xxx", so I want to create the folders Main and Characters. I tried using this method (after removing Player.xxx from the string)":

string syntax = "md "+path;
system(syntax.c_str());

However, '\' is counted as an escape and not a backslash, the optimal solution is to replace every '\' with a '\' but that would increase my tool from O(n) to O(2n) given that it needs 30 seconds to fully finish each part. Is there a way to use Raw strings in Code::Blocks? as R"(\w\\\w)"; didn't do the job for me. (R is not declared in this scope).

Any other solution that doesn't revolve around Raw strings is also welcome.

Torbjörn
  • 4,822
  • 4
  • 44
  • 70
thethiny
  • 852
  • 1
  • 7
  • 19
  • 5
    Just to be clear, O(n) and O(2n) are the same. – GManNickG Aug 04 '16 at 21:00
  • And O(1) can take a billion years or more. – user4581301 Aug 04 '16 at 21:02
  • @GManNickG I know that they're the same, but think of it logically. – thethiny Aug 04 '16 at 21:15
  • 3
    I know what you mean, but just say "then I have to iterate twice", which is simpler and clearer. :) Anyway, Code::Blocks is an IDE, not a language. C++11 supports raw strings, and if you're getting errors using them then you just need to enable C++11 support in your compiler. – GManNickG Aug 04 '16 at 21:20
  • @GManNickG I guess I'll do what you say then. – thethiny Aug 04 '16 at 21:25
  • The amount of time taken to insert the `'\\'` is likely dwarfed by the cost of the `system` call and the making of the directory. Don't expect a noticeable performance improvement from this unless something has gone seriously wrong. – user4581301 Aug 04 '16 at 21:41
  • @user4581301 So relatively it's fast. Anyways I optimized it as much as possible (Reading the entire file byte by byte and automatically strong a string into a a variable string, and each '\' adds another one after it. So I kept it O(n). Thanks to everyone who contributed. – thethiny Aug 04 '16 at 23:09

2 Answers2

0

Answer 1 - Upgrade to another Compiler. Answer 2 - Simply replace every \ with \

thethiny
  • 852
  • 1
  • 7
  • 19
0

Go to Settings>Compiler, then check the box next to where it says have g++ follow the C++11 ISO C++ language standard.

This will allow you to use the features introduced by the 2011 standard, which includes the R prefix.

John
  • 1