Home > Back-end >  Press space to read a file and a newline
Press space to read a file and a newline

Time:09-30

File the string arrangement is as follows:
001 student2 student1
003 student2 student1 student3
Student3 008

Want to read the following: in the vector
Struct Course
{
Char ID [5];
Vector};
Vector VecCourse;

No output after the following code execution, feel is a problem over there to read a newline, but don't know how to change
The FILE * pfile=NULL;
Fopen_s (& amp; Pfile, "d: \ \ data_stu \ \ coursemember TXT", "r");
If (pfile==NULL)
{
Printf (" error! \n");
The exit (0);
}
Course Course;//create a new Course type variable is used to read data in temporary storage file
Char * stuname;
While (1)
{
Fscanf_s (pfile, "% s", course ID, 5);
If (feof (pfile)) break;//end of file to exit the loop
While (1)
{
Char * stuname=new char;//make sure every time a push into different Stulist address
Char ch=fgetc (pfile);
If (ch!='\ n')//determine whether line breaks
{
Fscanf_s (pfile, "% s", stuname);
Course. Stulist. Push_back (stuname);
}
The delete stuname;
If (ch=='\ n') break;//out of the inner loop
}
VecCourse. Push_back (course)//; Push the course into the vector
}
The fclose (pfile);

//output just import the contents of the
For (unsigned int I=0; I & lt; VecCourse. The size (); I++)
{
Cout & lt; Unsigned int j=0;
for (; J & lt; VecCourse [I] Stulist. The size () - 1; J++)
{
Cout & lt; }
Cout & lt; }
  • Related