Enter a filename and path to create the file, save the input from the keyboard to the file, and finally output the path to the file, the file name, and the contents of the file to the screen.
#include <iostream> #include <fstream> #include <string> using namespace std;
int const SIZE=80;
void GetFileName (char arr[]);
void GetFilePath (char arr[]);
int main () {char arr[size];
String str;
cout<< "Please enter file path and filename:" <<endl;
Cin.getline (arr,size);
Cin.getline (Arr,size, ' # ');//cin.getline (character pointer (char*), number of characters n (int), Terminator (char));
Ofstream ofile (arr,ios_base::out); if (!ofile) {cout<< "error!"
<<endl;
return 0;
} cout<< "Please enter content:" <<endl;
Getline (Cin,str, ' # ');
ofile<<str<<endl;
GetFileName (arr);
GetFilePath (arr);
Ifstream ifile (arr,ios_base::in);
cout<< "File content:" <<endl;
while (!ifile.eof ()) {getline (IFILE,STR);
cout<<str;
} cout<<endl;
return 0;
} void GetFileName (char arr[]) {int temp,j;
int i=0;
Char Filename[size];
while (arr[i++]!= ') {if (arr[i]== ' \ \ ') {temp = i;
}//i++;
} int k=0; for (i=temp+1; arr[i]!= '); i++) {Filename[k++]=arr[i];
} filename[k]= ' + ';
cout<< "file name:" <<fileName<<endl;}
void GetFilePath (char arr[]) {int temp;
int i=0;
Char Filepath[size];
while (arr[i++]!= ') {if (arr[i]== ' \ \ ') {temp = i;
}} for (i=0; i<temp; i++) {filepath[i]=arr[i];
} filepath[temp]= ' + ';
cout<< "File path:" <<filePath<<endl;
System ("pause"); }