| | |
create, write & read file to/from folder
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
hello.. help me solve this :cheesy:
when a new car or motorcycle created, the system should create a folder with the name of the car or motorcycle. the hierarchy should be like this:
Vehicle(main exe folder)
+Car
-Porsche
-Ferrari
+Motorcycle
-Suzuki
-Honda
new vehicle info's folder shoud be create as example
---> c:\vehicle\motorcycle\suzuki125\
---> c:\vehicle\car\ferrari\ferrariSE\
so, from C++
- how to create new folder?
- how to create new file in new folder?
- how to write/read file from the folder?
when a new car or motorcycle created, the system should create a folder with the name of the car or motorcycle. the hierarchy should be like this:
Vehicle(main exe folder)
+Car
-Porsche
-Ferrari
+Motorcycle
-Suzuki
-Honda
new vehicle info's folder shoud be create as example
---> c:\vehicle\motorcycle\suzuki125\
---> c:\vehicle\car\ferrari\ferrariSE\
so, from C++
- how to create new folder?
- how to create new file in new folder?
- how to write/read file from the folder?
Last edited by n3st3d_l00p; Sep 23rd, 2006 at 8:17 am.
so, from C++
- how to create new folder?
- how to create new file in new folder?
- how to write/read file from the folder?
To create a folder do this:
- how to create new folder?
- how to create new file in new folder?
- how to write/read file from the folder?
To create a folder do this:
C++ Syntax (Toggle Plain Text)
#include <direct.h> int main() { mkdir("c:/myfolder"); }
*Voted best profile in the world*
To create new file in folder do this:-
And so on.
C++ Syntax (Toggle Plain Text)
#include <direct.h> #include <fstream> using namespace std; int main() { mkdir("c:/myfolder"); ofstream write ("c:/myfolder/myfile.txt"); write << "Sup mo fo"; write.close(); }
And so on.
*Voted best profile in the world*
•
•
•
•
how to create from input?
string folder;
getline(cin, folder);
mkdir(folder); ???
cannot compile!
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <direct.h> int main(int argc, char** argv) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " [new dir name]\n"; return(EXIT_FAILURE); } if (mkdir(argv[1]) == -1) { // Create the directory std::cerr << "Error: " << strerror(errno); return(EXIT_FAILURE); }
The key to eliminating bugs from your code is learning from your mistakes.
Since
mkdir() is not a standard C/C++ function, it's not surprising it doesn't work. The standard language is designed to be ignorant of the 'outside world' (directories, screen, keyboard) so anything that uses them outside the rudimentary I/O is compiler dependant. You'll have to look through your compiler documentation to see what functions it provides. The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
•
•
Through Command Line
}C++ Syntax (Toggle Plain Text)
#include <iostream> #include <direct.h> int main(int argc, char** argv) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " [new dir name]\n"; return(EXIT_FAILURE); } if (mkdir(argv[1]) == -1) { // Create the directory std::cerr << "Error: " << strerror(errno); return(EXIT_FAILURE); }
how should i use these? run at cmd line? :rolleyes:
How about working with const char arrays instead?
or look into using c_str() with std::strings?
C++ Syntax (Toggle Plain Text)
#include <direct.h> #include <fstream> #include <iostream> #include <cstring> using namespace std; int main() { char folder[101]; cout << "Name your folder mo fo:"; cin >> folder; char path[]="c:/"; strcat(path,folder); mkdir(path); cout<<"Folder added to c: drive"; cin.get(); }
or look into using c_str() with std::strings?
*Voted best profile in the world*
![]() |
Other Threads in the C++ Forum
- Previous Thread: VC++2005 express help
- Next Thread: need debugging help.. i've look at this too long
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






