Ich möchte einen Ordner erstellen und dann meine Datei in diesem Ordner speichern. Ich habe Code geschrieben, der automatisch eine Datei erstellt und ich möchte die Datei in einem Ordner speichern. Ich habe viele Codes ausprobiert, aber keine funktioniert. Unten ist meine letzte Code, habe ich versucht, aber es funktioniert immer noch nicht:Wie erstellt man Datei und Ordner und speichert diese Datei in einem Ordner?
void rooms() {
Name rooms;
Name rooms2;
Name rooms3;
Name staff;
int b;
char choicedo;
string filename;
string input;
do
{
ofstream bilik2;
bilik2.open("rooms2.txt", ios::out | ios::app);
if(!bilik2)
{
cout<<"File Not Found!";
exit(1);
}
if(bilik2 == NULL)
{
cout << "Error! Rooms is empty!";
break;
}
ofstream bilik3;
bilik3.open("rooms3.txt", ios::out | ios::app);
if(!bilik3)
{
cout<<"File Not Found!";
exit(1);
}
if(bilik3 == NULL)
{
cout << "Error! Rooms is empty!";
break;
}
cout<<"1. Single Rooms "<<endl;
cout<<"2. Family Rooms "<<endl;
cout<<"3. Royal Rooms "<<endl;
cout<<endl;
cout<<"\nRooms type: ";
cin >> b;
system("cls");
cout<<"Please fill in requirement information "<<endl;
switch(b)
{
case 1:
{
cout<<"Room No: ";
cin>>filename;
input = filename;
cin.ignore();
//ofstream input("C:\\Users\\Dr. Akilah\\Desktop\\BLUE\\single room");
mkdir("singleroom");
ofstream outfile("singleroom");
//system("mkdir singleroom");
outfile.write(input.c_str(), input.size());
input += ".txt";
outfile.close();
ifstream ifile(input.c_str());
if(ifile)
{
cout<<"Room is already exist."<<endl;
exit(1);
}
ofstream out(input.c_str());
//out.open("C:/Users/Dr. Akilah/Desktop/BLUE/single room/ ", ios::out | ios::app);
ofstream bilik;
bilik.open(input.c_str(), ios::out | ios::app);
cout<<endl;
cout<<"Air Conditioner: ";
cin.getline(rooms.airc, 20);
cout<<"Date: ";
cin.getline(rooms.date, 20);
cout<<"Insert by: ";
cin.getline(staff.first, 20);
bilik<<"List of Single Rooms"<<endl;
cout<<endl;
bilik<<"------------------------------------------------------------"<<endl;
bilik<<endl;
bilik<<" Room No: "<<filename<<endl;
bilik<<endl;
bilik<<"Air Conditioner: "<<rooms.airc<<endl;
bilik<<endl;
bilik<<"Regsitration Date: "<<rooms.date<<endl;
bilik<<endl;
bilik<<"Created by: "<<staff.first<<endl;
bilik<<endl;
bilik<<endl;
bilik<<"------------------------------------------------------------"<<endl;
bilik.close();
break;
}
case 2:
{
cout<<endl;
cout<<"Room no: ";
cin>>rooms2.room;
cin.ignore();
cout<<"Air Conditioner: ";
cin.getline(rooms2.airc, 20);
cout<<"Date: ";
cin.getline(rooms2.date, 20);
cout<<"Insert by: ";
cin.getline(staff.first, 20);
break;
}
case 3:
{
cout<<endl;
cout<<"Room no: ";
cin>>rooms3.room;
cin.ignore();
cout<<"Air Conditioner: ";
cin.getline(rooms3.airc, 20);
cout<<"Date: ";
cin.getline(rooms3.date, 20);
cout<<"Insert by: ";
cin.getline(staff.first, 20);
break;
}
default:
cout<<"Invalid choice "<<endl;
cout<<endl;
Sleep(1000);
//return 0;
}
cout<<"Enter Y To input an other data or Enter N to Exit: ";
cin>>choicedo;
cout<<"_____________________________________"<<endl;
cout<<endl;
}
while (choicedo=='y' || choicedo=='Y');
}
Wenn ich kompilieren diesen Code:
Dieser Fehler erscheint:
Also, wie kann ich diesen Fehler beheben? Und wie kann ich meine Datei in einem Ordner speichern?
Klicken Sie auf diesen Link, um meine Fotos zu sehen. Entschuldigung für etwaige Unannehmlichkeiten, dies ist das erste Mal, dass ich diese Website nutze. Vielen Dank. –
Veröffentlichen Sie keine Links zu Bildern von Text. Veröffentlichen Sie nicht einmal Bilder von Text. Kopieren Sie den tatsächlichen Text stattdessen in den Text der Frage. Bitte [lesen Sie, wie Sie gute Fragen stellen können] (http://stackoverflow.com/help/how-to-ask). Sie sollten wahrscheinlich lernen, wie Sie ein [minimales, vollständiges und überprüfbares Beispiel] erstellen können (http: // stackoverflow.com/help/mcve). –
Übrigens, was * ist * deine Frage? Geht es um den Buildfehler? Oder wie erstellt man einen Ordner und erstellt dann eine Datei in diesem Ordner? Eine Frage pro Frage bitte! –