There is a txt file "semiya.txt" in which there is a list:

мама папа брат сестра 

(in the column). We need to create another txt file "ishod.txt", which would look like this:

 0="мама", 1="папа", 2="брат", 3="сестра", 

(after the comma a new line begins, i.e. also in the column).

Tell me how to implement this in C ++!

    2 answers 2

    In this spirit:

     string line; ifstream source ("from.txt"); int i = 0; if (source.is_open()) { while (source.good()) { getline(source, line); cout << i++ << "=\"" << line << "\"" << endl; } source.close(); } 

    Outputting you as an exercise.

      Open the semiya.txt file for reading,

       FILE *semia = fopen("semia.txt","r"); 

      and the ishod.txt file is written,

       FILE *ishod = fopen("ishod.txt","w"); 

      and set the row count.

       int k = 0; 

      We read line by line (but in the case of your file format is more convenient word for word )

       char w[100]; while (fscanf(semia,"%s",w) == 1) 

      semia.txt. After reading the line (words), we form a line in the ishod.txt file and increment the counter.

      Sort of:

       fprintf (ishod,"%d=\"%s\",\n",k++,w); 

      Actually everything. Happy New Year !