0

I'm new to C++ and programming in general and I would like to know if there is a way to separate a line from a text file into different variables. For example, I want to separate this:

GreenTea limited 24 Instock

And assign each word/number into different variables:

string product;
string type;
int code;
string availability;

How can I achieve this easily? I've used a for loop so that I can find a space and take the substring of the word in order to separate it, but this seems highly inefficient and time consuming.

  • 1
    `std::istringstream ss("GreenTea limited 24 Instock"); ss >> product >> type >> code >> availability;` – Igor Tandetnik Feb 28 '21 at 16:53
  • 1
    Related: https://stackoverflow.com/questions/7868936/read-file-line-by-line-using-ifstream-in-c – Bob__ Feb 28 '21 at 16:58
  • I mean this with respect, but stackoverflow is not a place to learn how to program. Please look into an online class or book or something for learning a new language. – Mooing Duck Feb 28 '21 at 16:59

0 Answers0