| | |
Writing to a file
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 179
Reputation:
Solved Threads: 2
Hi all
My friend sent me a source file that wrote hello world to a text file (im a noob), I tried to modify it and give myself a challange to make a small database but it has gone horribly wrong. I dont know how to get it so when the person enters n it goes back to the start of the program, but im also getting errors all over the shop.
Here are the error messages coming up, im using Dev C++ Beta 5.something
1)answer does not name a type
2)djout undeclared
3)unknown escape sequence /T
4)getline undeclared
5)answer undeclared
Thanks for your help
HLA91
My friend sent me a source file that wrote hello world to a text file (im a noob), I tried to modify it and give myself a challange to make a small database but it has gone horribly wrong. I dont know how to get it so when the person enters n it goes back to the start of the program, but im also getting errors all over the shop.
Here are the error messages coming up, im using Dev C++ Beta 5.something
1)answer does not name a type
2)djout undeclared
3)unknown escape sequence /T
4)getline undeclared
5)answer undeclared
c++ Syntax (Toggle Plain Text)
#include<fstream>// headerfile for output/input #include<iostream> #include<string> using namespace std; int main() { string personname; string activity; string arriving; string answer ofstream djout; // declare our djoutput djout.open("C:\TEST.txt"); // opens/creates and edits "TEST.txt" cout << "Please enter the persons name: "; getline (cin, personname); cout << "Please enter the activity: "; getlline (cin, activity); cout << "How are they arriving: "; getline (cin, arriving); cout << "Please confirm the details: "; cout << "Name: " << personname << endl; cout << "Activity: " << activity << endl; cout << "Arriving by: " << arriving << endl; cout << "Are the details correct? Y/N" << endl; getline (cin, answer); if (answer == 'y') { djout << personname << endl; djout << activity << endl; djout << arriving << endl; djout.flush(); // to save the file, you must close the file, or flush djout.close(); // the buffer to the file Closing the file will not let // you access it anymore, so only call it when you are // done using the file and it will automatically save // the file for you. Flushing the buffer will write the // buffer to the file and still keep the file open, so // use this function when necessary. } if (answer == 'n') { //I want it to go back to the beginning of the program } else { cout << "System error sorry guys im not always right :)" << endl; } system("pause"); return 0; }
Thanks for your help

HLA91
Last edited by Ancient Dragon; Nov 28th, 2007 at 1:49 pm. Reason: add line numbers to existing code tags
line 13 -- you forgot the semicolon at the end.
line 15: need to escape the '\' character
I'm not going to tell you the rest of the errors. Just fix them one at a time and compile after each correction.
line 15: need to escape the '\' character
djout.open("C:\\TEST.txt"); I'm not going to tell you the rest of the errors. Just fix them one at a time and compile after each correction.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Redirecting console output to file (Java)
- Read/write to same file > once, Help (C++)
- ofstream - detect if file has been deleted between open and close (C++)
- A question about file streaming (C++)
- writing to a file (Java)
- Saving a file (Java)
- file input and output (C)
Other Threads in the C++ Forum
- Previous Thread: Problem with Sort() file TXT
- Next Thread: Adding arrays, selections, and a quit option
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






