example3_using_a_delimiter.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
#include <sstream>

int main() {
    std::string input = "apple,banana,cherry,date";
    std::istringstream iss(input);
    std::string fruit;
    
    std::cout << "Fruits:\n";
    while (std::getline(iss, fruit, ',')) {
        std::cout << "- " << fruit << std::endl;
    }
    
    return 0;
}
Back to std_getline