| | |
WritetoFile() order is messed
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi all
I have a function writetofile() which save a record to a file but the problem is when its writting to a file it doesnt write the record in a correct order, here is the code for WriteToFile()
Now the problem is when it is saving a record to a file it 1st write the Count which is correct, from there it writes the Name instead of StudentNo, followed by Surname, DateofBirth, Gender, Mark and StudentNo, if u know why it is messing up my record please I need ur help urgent, coz the order should be like the way it is on the WriteToFile() method but it isnt, I hope this make sense
Thanks in Advance
I have a function writetofile() which save a record to a file but the problem is when its writting to a file it doesnt write the record in a correct order, here is the code for WriteToFile()
c++ Syntax (Toggle Plain Text)
void StudentC::WriteToFile() { ofstream Outfile; Outfile.open("File\\Student.txt", ios::app); Outfile << Count << endl; Outfile << StudentNo << endl; Outfile << Name << endl; Outfile << Surname << endl; Outfile << Gender << endl; Outfile << DateOfBirth << endl; Outfile << Mark << endl; Outfile.Close(); }
Now the problem is when it is saving a record to a file it 1st write the Count which is correct, from there it writes the Name instead of StudentNo, followed by Surname, DateofBirth, Gender, Mark and StudentNo, if u know why it is messing up my record please I need ur help urgent, coz the order should be like the way it is on the WriteToFile() method but it isnt, I hope this make sense
Thanks in Advance
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
•
•
Join Date: Apr 2009
Posts: 30
Reputation:
Solved Threads: 1
Let me tell you something. You cut a part of your code and put it here, and when we try to figure out what's wrong, we are totally lost. hehehe, seriously!
But, first of all, it's "Outfile.close" not "Outfile.Close".
Second of all, There is nothing wrong with your code. But here are some pointers:
* Try to delete the Student.txt from your folder and run the program that I copied here and see the result.
* You explained why you used app, so beware of the outcome.
* You don't write your variables name like the way you do in human language. What I mean is, there are some conventions that you should follow. As far as I know, System Programmers and Unix programmers, use "_" kind of format, Like:
int pointer_to_file;
But Object oriented programmers and framework programmers use FIRST SMALL, REST BIG(I just made it up!!!). Means it's gonna be like:
int pointerToFile;
It's up to you how to use it, but I think you'd better at least follow a convention to give some professional look to your program. Professionals, please correct me if I'm wrong.
And after all the story here goes the code, just copy and paste it and compile...
But, first of all, it's "Outfile.close" not "Outfile.Close".
Second of all, There is nothing wrong with your code. But here are some pointers:
* Try to delete the Student.txt from your folder and run the program that I copied here and see the result.
* You explained why you used app, so beware of the outcome.
* You don't write your variables name like the way you do in human language. What I mean is, there are some conventions that you should follow. As far as I know, System Programmers and Unix programmers, use "_" kind of format, Like:
int pointer_to_file;
But Object oriented programmers and framework programmers use FIRST SMALL, REST BIG(I just made it up!!!). Means it's gonna be like:
int pointerToFile;
It's up to you how to use it, but I think you'd better at least follow a convention to give some professional look to your program. Professionals, please correct me if I'm wrong.
And after all the story here goes the code, just copy and paste it and compile...
C++ Syntax (Toggle Plain Text)
#include <fstream> using namespace std; void WriteToFile(); int main() { WriteToFile(); return 0; } void WriteToFile() { int Count = 10, StudentNo = 102211; string Name = "Tom", Surname = "Hanks", Gender = "Male", DateOfBirth = "8/14/2009"; double Mark = 15.5; ofstream Outfile; Outfile.open("Student.txt", ios::app); Outfile << Count << endl; Outfile << StudentNo << endl; Outfile << Name << endl; Outfile << Surname << endl; Outfile << Gender << endl; Outfile << DateOfBirth << endl; Outfile << Mark << endl; Outfile.close(); }
Last edited by group256; Aug 14th, 2009 at 11:46 am.
![]() |
Similar Threads
- AS3 FocusManager, tabIndex and tab loop control in flash form components (Graphics and Multimedia)
- php order form help (PHP)
- PLEASE HELP ME math problem I FEEL LIKE CRYING!! (PHP)
- Help with a date loop & error '80020009' (ASP)
- messed up windows... again! (Windows NT / 2000 / XP)
- Changing Startup Programs Order (Windows NT / 2000 / XP)
- pixles and colors messed up (Windows 95 / 98 / Me)
- Msn buddy icons messed up (Windows Software)
- DOS C++, pulling boot order and hard drive parameters, (C++)
Other Threads in the C++ Forum
- Previous Thread: Urgent Help Need!!
- Next Thread: CDialog - Assertion failure
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






