简体   繁体   中英

How do I place a multidimensional array from a .txt file into code and print out one line at a time?

I have a .txt file that looks like this:

<object1><object2><object3>
Value 1 | Value 2 | Value 3

The file actually contains about 50 columns and over 500K rows.

I am creating a program that duplicates this information to another text file with a momentary pause between each line print.

my trouble is that I am confused as to how to bring the info in, and print out 1 line at a time to the new text file.

I know how to open and read the original file. I know how to create a new file and put the data in. and I know how to slow it down. But as you can tell, I am new to C++ and programming in general and I am trying to better understand arrays. To be clear, this is not for a class or any homework, im just a generally confused dude haha.

If you just want to transfer a file line by line to another file, this could look as follows:

char line[1000];
while (fgets(line,1000,infile)) {

  // wait or do anything needed in between
  int rc = fputs(line,outfile);
  if (rc == EOF)
    break;
}

If you have to do any transformations, then change line accordingly before writing. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM