Dead simple, incomplete file editor.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
int mb_result;
string edit;
string content;
string location;
cout<<"\n TXT READER\n\n\n NOTE: This program is used for reading\n txt documents only.\n\n\n";
cout<<" Text file you wish to read:\n\n ";
getline (cin, location);
ifstream a_file (location.c_str());
a_file>> content;
if ( a_file.fail() )
{
mb_result = MessageBox(NULL, " Failed to locate/read a file.\n Do you wish to try again ? ", " Text.exe", MB_YESNO | MB_ICONEXCLAMATION);
while ( mb_result == IDYES && a_file.fail() )
{
a_file.close(); // Close existing stream before opening again. (Bottom of while loop.)
a_file.clear(); // Clear the stream status.
system("cls");
cout<<"\n TXT READER\n\n\n NOTE: This program is used for reading\n txt documents only.\n\n\n";
cout<<" Text file you wish to read:\n\n ";
getline (cin, location);
a_file.open(location.c_str());
a_file>> content;
}
}
if ( a_file.is_open() )
{
cout<<"\n\n\n This is the content of the file:\n\n "<<content<<"";
cin.get();
}
}
I understand that if I put the window handle instead of NULL when creating the message box, it will be 'part of' that window, but as far as I'm concerned, my window has no handle.
Thanks