| wr0124 (9) | |
|
hi, I have on code, but I don't know how to improve it. To make the result.txt in the newly created directer ? The code are following : #include<iostream> #include<stdlib.h> #include<ctime> #include<time.h> #include<fstream> #include<stdlib.h> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<sys/stat.h> using namespace std; int main() { int n; cout<<"paramater for p and N: "; cin>>n; char folder[101]; cout<<"name your folder no fo: "; cin>>folder; char path[]="//Users//rw36//Desktop//new"; strcat(path, folder); mkdir(path,0777); cin.get(); ofstream ou("result.txt" , ios::out); for ( int i=0; i<10; i++) { ou<<i*10<<endl; } return 0; } | |
|
|
|
| kbw (5375) | |
| Use are you not using std::string instead of those misused char arrays? | |
|
|
|
| wr0124 (9) | |
|
sorry, i don't know what it is. can you correct me the code ? Thanks ? how to make "result.txt" generated inside the directer named as path ?... | |
|
|
|
| kbw (5375) | |||
I've not compiled it, but this is what I had in mind. There may be an issue with the directory creation, but one thing at a time.
| |||
|
Last edited on
|
|||
| wr0124 (9) | |
|
thanks. yes, you are right,,, it had been solved... #include <unistd.h> #include <iostream> #include <fstream> #include <string> #include<sys/stat.h> using namespace std; int main() { int n; cout << "paramater for p "; cin >> n; string folder; cout << "name your folder no fo: "; cin >> folder; string path = "/Users/rw36/Desktop/new"; path += folder; mkdir(path.c_str(), 0777); string filename = path + "/result.txt"; ofstream ou(filename.c_str(), ios::out); for ( int i=0; i<n; i++) { ou<<i*n<<endl; } return 0; } | |
|
Last edited on
|
|