dimanche 28 février 2021

How to separate a line into different variables in C++

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.

Aucun commentaire:

Enregistrer un commentaire