I am suppost to make this for my class and i need help.. This is what i have so far i am not currently working on read files yet but writing files and i am having some problems. This is what my output looks like
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
#include "conio.h"
usingnamespace std;
void filewrite()
{
ofstream myfile;
myfile.("Test.txt");
myfile<<"testing testing!\n";
myfile.close();
}
void createfile()
{
string extention;
string filename1;
string Filewrite;
system("cls");
cout<< " Creating File to Read Later on from this Win32 Console or from Documents"<<endl;
cout<< "\n\n What kind of extention will you use? ('example-.txt, .exe, .doc ')"<<endl;
cin>>extention;
system("cls");
cout<< " Please Give the Name of the File ! "<<endl;
cout<< " Name:";
cin>>filename1;
Sleep(2000);
cout<< " Please wait while the system Process"<<endl;
Sleep(2000);
system("cls");
cout<< " Writing on "<<filename1<<extention<<" , Please Write what you would like to write on the file"<<endl;
cin>>Filewrite;
filewrite();
_getch();
}
int quit()
{
cout<<"Press Enter again to Quit"<<endl;
_getch();
return 0;
}
void read()
{
cout<< "Read"<<endl;
_getch();
}
int main()
{
main:
system("cls");
system("color 0a");
main;
int end;
int end2;
int choicemain;
cout<< " CHOOSE YOUR PATH "<<endl;
cout<< "\n\n\n\n1. Create a File"<<endl;
cout<< "\n2. Read contents of a File"<<endl;
cout<< "\n3. Quit"<<endl;
cin>>choicemain;
switch(choicemain)
{
case 1:{ createfile();}
break;
case 2:
{
read();
}
break;
case 3:
{
cout<<"Press Enter again to Quit"<<endl;
_getch();
return 0;
}
break;
default: {
cout<< " Wrong Selection"<<endl;
Sleep(2000);
goto main;
}
break;
}
end:
system("cls");
cout<< "Would you like to do it again? (1 = Yes) (2 = Quit)"<<endl;
cin>>end;
switch(end)
{
case 1:{
goto main;
break;
}
case 2:{
quit();
break;
}
default: { cout<<" Wrong selection "<<endl;
Sleep(2000);
goto end;
}
break;
}
}
can anyone tell me how to write the file because i am lost and have no idea how to do this... Sorry i don't have any comments
#include <fstream>
#include <string>
usingnamespace std;
int main(){
fstream file;
string filename = "output.txt";
//This is simply a default initializer, since we haven't gotten the file name from the user
//Receive file's path/name.extension from user here store in "filename" string
file.open(filename.c_str(),ios::out);
// change to (filename.c_str(),ios::out|ios::app) if you want to append
string output = "hello world";
//Receive output from user here store in "output" string
file << output;
file.close();
}
Answers: Number 1 - I need it to put _getch (); and its causing no problem .
Number 2 - This Fixed my Problem.
Number 3 - just wanted to make it seem professional
Number 4 - I need a Menu for my class project an interface
@Number 1: I know. You're compiler is being a champ.
@Number 2: I figured.
@Number 3: goto = not super professional (IMHO)
@Number 4: I know. That's what the //comments were referring to.