Changing the current directory in Linux using C++

前端 未结 3 681
余生分开走
余生分开走 2021-01-02 16:29

I have the following code:

#include 
#include 
#include 

using namespace std;

int main()
{
    // Variables
          


        
3条回答
  •  盖世英雄少女心
    2021-01-02 17:20

    The issue is that you are string to pass an STL string to chdir(). chdir() requires a C Style string, which is just an array of characters terminated with a NUL byte.

    What you need to be doing is chdir(sDirectory.c_str()) which will convert it to a C Style string. And also the int on int chdir(sDirectory); isn't necessary.

提交回复
热议问题