Problem Retreving data from txt file

When i execute the program it gets the right data for the first array but the scound either doesn't work at all or just gets to much data. i've tryed using getline and the "cin" for what the file would be in this case "myfile" there is also one more array that must be retrieved from the file. thank you in advance for any help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char *sAnswers,*answers,*studentId;
char sa[20], a[20], sId[20];

int main () {
  string line;
  ifstream infile;
  ifstream myfile ("students.txt");
  
  if (myfile.is_open())
  {
    myfile.getline(a,20);
    cout<<a<<endl;
    myfile.getline(sId,20);
    myfile.ignore(' ');
    cout<<sId;
    
    
    
      }

  else cout << "Unable to open file"; 

  system ("pause");
}
I am just looking for a hint i will admit this is homework but i'm not understanding the problem with the program as i've searched online ,in the archives, and have tried to fix it many different ways. if it makes any difference the text file reads as


"TFFTFFTTTTFFTFTFTFTT

ABC54301 TFTFTFTT TFTFTFFTTFT
"

the space between the second set of T and F's is supposed to be there and put into the same array
Last edited on
I would look into myfile.ignore(' '); in line 19. For now it tells it to skip 32 symbols.

Maybe you want myfile.ignore(std::numeric_limits<std::streamsize>::max(), ' '); to skip all symbol until space is encountered?
it had the same output as everything else, i did try this but would there be a way to change upmyfile.ignore(20,' ') being that it would also make the parameters 20 characters?
If i'm reading correctly would the myfile.ignore(std::numeric_limits<std::streamsize>::max(), ' '); only ensure that the first array 'a' gets the correct information? how would you skip to the next line to get the next set of information the "ABC543210" and so on?
Topic archived. No new replies allowed.