How return a std::string from C's “getcwd” function

后端 未结 7 536
我寻月下人不归
我寻月下人不归 2021-01-20 07:35

Sorry to keep hammering on this, but I\'m trying to learn :). Is this any good? And yes, I care about memory leaks. I can\'t find a decent way of preallocating the char*, be

7条回答
  •  旧时难觅i
    2021-01-20 08:04

    You need to check for a_cwd being NULL. Then it will work on Mac, Windows, Linux. However, it's not POSIX-compliant.

    EDIT: perror doesn't exit the program, so you should exit, throw an exception, or do something.

提交回复
热议问题