| | |
Difficulty understanding Object Orientated File Streaming
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
Well, not so much difficulty, more like I am completely stumped!
I've only been programming with c++ for a few weeks, yet I have found myself in the predicament of having a small, albeit difficult assignment to complete for university pretty soon. I was wondering if anyone could help me.
Basically, we've been given a small piece of code which controls a program that opens/closes input/output .txt files;
if (argc !=3) {
cerr << "Usage: " << argv[0] << " <input filename> <output filename>" << endl;
int keypress; cin >> keypress;
return -1;
}
The program performs three tests to determine the validity of input/output files.
I had to create a .cpp and .h file to accommodate a copy() method which performs the following functions;
Test for the existence of the input file.
Open the input file
Create the output file
Read each line of text from the input file and output the line to the output file
Return true if the file has copied or return false for any other reason
This method has to be called from the main class as highlighted above.
I'm confused about a lot of things really. How to declare an instance of secondary classes in the main class, using objects as parameters. The whole #include thing for the seperate classes. And just, you know, how file streaming works in a object orientated sense. I understand the need to #include the fstream library, but how do I know which of it's functions to use. I am running visual studio.net
If anyone could help me, or point me in the right direction I would be eternally grateful!
Thanks in advance.
Edit: I don't want a solution for this, I just need some help understanding the concepts. I feel like we haven't been taught this stuff properly (well, not at all) in lectures. This seems to aid the students with a stronger programming background, unlike myself.
I've only been programming with c++ for a few weeks, yet I have found myself in the predicament of having a small, albeit difficult assignment to complete for university pretty soon. I was wondering if anyone could help me.
Basically, we've been given a small piece of code which controls a program that opens/closes input/output .txt files;
if (argc !=3) {
cerr << "Usage: " << argv[0] << " <input filename> <output filename>" << endl;
int keypress; cin >> keypress;
return -1;
}
The program performs three tests to determine the validity of input/output files.
I had to create a .cpp and .h file to accommodate a copy() method which performs the following functions;
Test for the existence of the input file.
Open the input file
Create the output file
Read each line of text from the input file and output the line to the output file
Return true if the file has copied or return false for any other reason
This method has to be called from the main class as highlighted above.
I'm confused about a lot of things really. How to declare an instance of secondary classes in the main class, using objects as parameters. The whole #include thing for the seperate classes. And just, you know, how file streaming works in a object orientated sense. I understand the need to #include the fstream library, but how do I know which of it's functions to use. I am running visual studio.net
If anyone could help me, or point me in the right direction I would be eternally grateful!
Thanks in advance.
Edit: I don't want a solution for this, I just need some help understanding the concepts. I feel like we haven't been taught this stuff properly (well, not at all) in lectures. This seems to aid the students with a stronger programming background, unlike myself.
![]() |
Similar Threads
- Assignment - Object Orientated Analysis (OOA) (C++)
- Object is not being written into file!!! (C++)
- Flash Developers All Levels (Web Development Job Offers)
- R/GA Seeking Flash Dev's All Levels in NYC (Web Development Job Offers)
- A function which will transfer the data from a file to STL( vector or map) object. (C++)
- R/GA Flash Developers NYC and London (Web Development Job Offers)
- ofstream - detect if file has been deleted between open and close (C++)
- Saving a file using C++ (C++)
Other Threads in the C++ Forum
- Previous Thread: Counting characters and dispalying numbers
- Next Thread: type casting
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





