theres GOT to be a simple solution for this one. . .

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2006
Posts: 4
Reputation: Dj Enjoi is an unknown quantity at this point 
Solved Threads: 0
Dj Enjoi Dj Enjoi is offline Offline
Newbie Poster

theres GOT to be a simple solution for this one. . .

 
0
  #1
Apr 15th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,602
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1490
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: theres GOT to be a simple solution for this one. . .

 
0
  #2
Apr 15th, 2006
use the chdir() function instead of the system() because (1) its faster and (2) its safer
  1. chdir("c:\\");
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: Dj Enjoi is an unknown quantity at this point 
Solved Threads: 0
Dj Enjoi Dj Enjoi is offline Offline
Newbie Poster

Re: theres GOT to be a simple solution for this one. . .

 
0
  #3
Apr 15th, 2006
ok, now it says chdir is undefined... is there a header to accompany this function??
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 496
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: theres GOT to be a simple solution for this one. . .

 
0
  #4
Apr 15th, 2006
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().
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: Dj Enjoi is an unknown quantity at this point 
Solved Threads: 0
Dj Enjoi Dj Enjoi is offline Offline
Newbie Poster

Re: theres GOT to be a simple solution for this one. . .

 
0
  #5
Apr 15th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 4
Reputation: Dj Enjoi is an unknown quantity at this point 
Solved Threads: 0
Dj Enjoi Dj Enjoi is offline Offline
Newbie Poster

Re: theres GOT to be a simple solution for this one. . .

 
0
  #6
Apr 15th, 2006
ok i finally figured it out.. it was a header file indeed..
except it was #include<unistd.h>

thnx for the pointer.. Pe@cE
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: theres GOT to be a simple solution for this one. . .

 
0
  #7
Apr 15th, 2006
I think it also works with #include <direct.h>

  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <conio.h>
  4. #include <direct.h>
  5. //#include<unistd.h>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. chdir("C:\\Documents and Settings");
  11. system("tree");
  12. getchar();
  13.  
  14. return 0;
  15.  
  16. }

http://img476.imageshack.us/img476/5171/cut20ln.png
Piworld
[Tis simple as Pie]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC