| | |
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,820
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 classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java 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 vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






