There is a function that takes 2 arguments - QStringList and QString , where the sheet contains ne the number of lines and every fourth line from the sheet must be replaced with the string QString and eventually return QStringList with the replaced strings.

  • It does not do for other training tasks. - user194374
  • one
    And what is the actual problem? Or do you want to do it somehow so that it is very "short"? - isnullxbh
  • yes no, the problem is that I don’t see a solution yet. Yes, it may be easy for most of those who are here, but for the time being I am just learning. I try while through the iterator to do a foreach loop - where it will replace the selected values. - Tony Estakado

1 answer 1

Something I'm good today ... If you only learn, then hold.

With the modification of the original list:

 QStringList& f1(QStringList& list, const QString& string) { for (size_t i = 3; i < list.size(); i += 4) list[i] = string; return list; } 

With a copy of the source list:

 QStringList f2(const QStringList& list, const QString& string) { QStringList result; result.reserve(list.size()); for (size_t i = 0; i < list.size(); ++i) result.push_back(i % 4 == 3 ? string : list[i]); return list; } 
  • Thank you so much - I will study now). Honestly did not expect to help. - Tony Estakado