| | |
Help? reading from one file to another...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 3
Reputation:
Solved Threads: 0
Hi. I'm new here and would appreciate any help you can give me.
I am a college student and I'm supposed to do this assignment where I take data from one txt file and put it into another. This is step one of a larger project. I have some code done but it's not that good. The infile is data for grocery receipt tape with five pieces of data across it. I have the outfile creating itself but it only contains zero's- three of them for each variable I created? How do I specify what to read from the infile? I need to read the first three of the five items. Thanks!
I am a college student and I'm supposed to do this assignment where I take data from one txt file and put it into another. This is step one of a larger project. I have some code done but it's not that good. The infile is data for grocery receipt tape with five pieces of data across it. I have the outfile creating itself but it only contains zero's- three of them for each variable I created? How do I specify what to read from the infile? I need to read the first three of the five items. Thanks!
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; int item_number, item_name, unit_price; //declaring variables int main() { ifstream indata; indata.open("data.txt",ios::in); // opens the infile ofstream outdata; outdata.open("YourLastName_YourFirstName.txt",ios::out); //opens the outfile outdata<<item_number<<item_name<<unit_price; indata.close (); //closes the infile outdata.close (); // closes the outfile return 0; }
Last edited by Ancient Dragon; Oct 8th, 2008 at 7:50 am. Reason: add code tags
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
Well, you should be checking to see if your file pointers are valid or not before proceeding.
And you need to read the data from your infile before you can write it to your outfile. You can have a counter that counts how many elements you are reading from your infile, and write them to the outfile.
Ah yes and what Salem just said
And you need to read the data from your infile before you can write it to your outfile. You can have a counter that counts how many elements you are reading from your infile, and write them to the outfile.
Ah yes and what Salem just said
Last edited by stilllearning; Oct 8th, 2008 at 2:12 am.
•
•
Join Date: Oct 2008
Posts: 3
Reputation:
Solved Threads: 0
Thanks guys or gals. I did read around last night but I missed the code tag part. Sorry! So, I'm still working on this today. I added the error code for the file open and found out that I had assigned the incorrect file name so it wasn't opening correctly. Now, I just need to get the right thing read and I am in business!
Last edited by Student_ABC; Oct 8th, 2008 at 9:26 am.
![]() |
Similar Threads
- Reading from file, passing into function. (C)
- Help on a reading from a file programming (Java)
- Need help reading a file (C++)
- Reading a file into a Parallel Array (C++)
- problems with reading in file (C++)
- First year assigment on reading file, sorting and outputting invoice (C++)
- Error Message Concerning Reading File From A Drive (C++)
- reading a file into code (Java)
Other Threads in the C++ Forum
- Previous Thread: Some question for a good OOP design
- Next Thread: connecting client to server
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






