I want to change to the directory specified by the path. The filename is a string and is included in the path.
I have stored the filename in a string and I am adding this filename to the path. Next using chdir()
I am changing to the directory specified by the path.
I know that the filename can be specified in the path itself, but I want it to do it this way because the filename will be keep on changing.
int main()
{
system("echo -n '1. Current Directory is '; pwd");
std::string filename ("1184581000.pcd");
cout<<filename;
chdir("/home/usrn/pcd/"+ filename"");
system("echo -n '1. Current Directory is '; pwd");
return 0;
}
The result is:
error: expected ‘)’ before string constant
chdir("/home/usrn/pcd/"+ ls"");
error: cannot convert ‘std::__cxx11::basic_string<char>’ to ‘const char*’ for argument ‘1’ to ‘int chdir(const char*)’
chdir("/home/usrn/pcd/"+ ls"");