ok, i kinda feel like an idiot asking this, but here it goes

simple setup for example purposes.:


#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
system("cd\")
return 0;
}


ok, as you've prolly already noticed, the CD\ will return an error saying that there is an invalid terminator because of the "\" .. all i want to do is change directories lol.. can someone help me out. thnx

Recommended Answers

All 6 Replies

use the chdir() function instead of the system() because (1) its faster and (2) its safer

chdir("c:\\");

ok, now it says chdir is undefined... is there a header to accompany this function??

the escape character for a backslash is simply \\ - however, as Ancient Dragon says, CD\\ (or indeed any system() call) is unsafe. IIRC, chdir() is part of windows.h or conio.h depending on your implementation - it's not a standard header, but it's certainly better than system().

i appreciate the help, but it still is not working...
heres the setup i have right now

#include <stdio.h>
#include <windows.h>
#include <conio.h>

using namespace std;

int main()
{
chdir("C:\\");

return 0;

}


still says chdir is undeclared

ok i finally figured it out.. it was a header file indeed..
except it was #include<unistd.h>

thnx for the pointer.. Pe@cE

Member Avatar for iamthwee

I think it also works with #include <direct.h>

#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <direct.h>
//#include<unistd.h>
using namespace std;

int main()
{
chdir("C:\\Documents and Settings");
system("tree");
getchar();

return 0;

}

[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]
Piworld ™
[Tis simple as Pie]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.