>>but I can't figure out how that works.
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream in("filename.txt");
string line;
// read each line of the file
while( getline( in, line) )
{
//blabla do something this line
}
}
>>I can't find a way to take a specific line in a text file
You have to read each line one at a time until you get to the line that you want.
>>How can I get each number into its own array?
What kind of array? int array?
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<int> arry; // array of integers
ifstream in("filename.txt");
int num;
// read each line of the file
while( line >> num )
{
arry.push_back(num); // add the number to the array
}
}
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,950 posts
since Aug 2005