console Text Editor - Help Me
Jul 17, 2012 at 8:11am UTC
I have been trying for 2 days to get this lousy code to work. the code woks when the Write(); function is not a function and is in the main()function it just skips right over the file name input can someone please tell me whats wrong with my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include <iostream>
#include <string>
#include <fstream>
using std :: cin;
using std :: cout;
using std :: endl;
using std :: string;
using std ::ofstream;
using std::fstream;
using std ::getline;
using std ::end;
void Write()
{
ofstream outFile;
char FileName[12];
char FileData[256];
cout <<"FileName: " ; cin.getline(FileName,12);
cout << "Enter Text:\n" ; cin.getline(FileData,256);
outFile.open(FileName,12);
outFile << FileData;
outFile.close();
}
void Open()
{
string openName;
cout << "What file do you wish to open: " ;
cin >> openName;
fstream myFile(openName);
string line;
bool Exit = false ;
cout << "\n\n\n\n\n\n\n\n" ;
if (myFile.is_open())
{
while (!myFile.eof() )
{
getline(myFile, line);
cout << line << endl;
}
myFile.close();
} else
{
cout << "Error Can Not Open File: " << openName << endl;
}
}
void Pause()
{
char Ref;
cin >> Ref;
}
int main()
{
unsigned short Load = 2;
unsigned short Make = 1;
unsigned short Choice;
cout << "Do you want to...\n (1) Write a new file. \n (2) Load a file.\n Choice: " ;
cin >> Choice;
if (Choice == Load)
{
Open();
}
else if (Choice == Make)
{
Write();
} else
{
cout << "\nInvalid Choice! " ;
}
Pause();
return 0;
}
Jul 17, 2012 at 8:26am UTC
Anywhere you have cin >> ...;
you need a cin.ignore(80, '\n' );
after it to clear the buffer.
Last edited on Jul 17, 2012 at 8:26am UTC
Jul 17, 2012 at 8:34am UTC
Thank you soo much. i have never even heard of that function. im going to look up the definition :)
Topic archived. No new replies allowed.