Troudeloup
asked on
getline
I have a txt file with 4 lines
line1
line2
line3
line4
I want to use a loop to store each line into an element in an array
string line[10];
int n = 0;
while ( n < 5 )
{
// getline
n = n + 1;
}
return 0;
what is the syntax to read whole N th line in the file?
line1
line2
line3
line4
I want to use a loop to store each line into an element in an array
string line[10];
int n = 0;
while ( n < 5 )
{
// getline
n = n + 1;
}
return 0;
what is the syntax to read whole N th line in the file?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
while (getline(infile, line)) {
lines.push_back(line);
}
i don't get this part.
ok how about, can you show me how to get the N th line and ignore the loop for now?
lines.push_back(line);
}
i don't get this part.
ok how about, can you show me how to get the N th line and ignore the loop for now?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
string line;
ifstream filePtr("lines.txt");
getline(filePtr, line);
cout << line << endl;
return 0;
}
i got this error message
#include <windows.h>
using namespace std;
int main ()
{
string line;
ifstream filePtr("lines.txt");
getline(filePtr, line);
cout << line << endl;
return 0;
}
i got this error message
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ah duh >_<
ASKER
I want to read from a txt file.