This question has already been answered:

There is a string variable initialized in this way:

std::string str = "qwert\n" "khrkrvne\n" "hbkb124f";

Each line is separated from the other "\ n". How to work with each line separately?

Reported as a duplicate by PinkTux , ߊߚߤߘ , user194374, αλεχολυτ , Denis Bubnov 27 Feb '17 at 6:08 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Plus many options here: stackoverflow.com/questions/236129 (as many as 68 responses) - PinkTux
  • What does it mean to work separately? Find the division points of the substrings and "work" on health "separately" for as long as you want, what's the problem? If you need to explicitly parse the string into pieces, then say so. - AnT

1 answer 1

 istringstream input(str); vector<string> vs; for (string line; getline(input, line); ) { vs.push_back(line); } 

and do with strings in vs what you want ...