| | |
reading a text file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 98
Reputation:
Solved Threads: 2
I am attempting to read a text file.
I want to read values from a text file. Im making the text file so I can read it however. This is a simple example of what I was thinking:
////text file/////
1 2 3 4
5 6 7 8
9 10 11 12
////text file/////
How do I store these values into a 2 dimensional array?
C++ Syntax (Toggle Plain Text)
ifstream indata; indata.open(filename); if(!indata) { // file couldn't be opened } else { // file opened } // keep reading until end-of-file string data; while (getline(indata, data)) { //this is where i want to store values } indata.close();
I want to read values from a text file. Im making the text file so I can read it however. This is a simple example of what I was thinking:
////text file/////
1 2 3 4
5 6 7 8
9 10 11 12
////text file/////
How do I store these values into a 2 dimensional array?
Last edited by Nemoticchigga; Sep 8th, 2008 at 1:32 pm.
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
Set up your 2-D array of integers, then read values into the array with the
>> operator. C++ Syntax (Toggle Plain Text)
indata >> array[i][j];
![]() |
Similar Threads
- c++ reading text file (C++)
- How to select data frm text file based on a condition (C)
- Help with a 2D array from a text file (C++)
- read text file (C)
- Reading in a text file string is not complete (Pascal and Delphi)
- reading txt file into array (C++)
Other Threads in the C++ Forum
- Previous Thread: calling DLL from MATLAB: 'No methods for class' error
- Next Thread: problem trying to use alpha for switch statement
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker 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 rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






