如何在c++中从TXT文件中获取特定的数据



这是我第一次发表文章,我有一个问题我有一个。txt文件,我想用","分隔。例子:例二,example2,青年们,example4我想要获取example1并将其存储在一个数组中,以此类推example2, example3, example4。String [0] = example1String [1] = example2等等…

getline默认情况下将按行结束字符分割输入,但可以对任何字符进行分割,包括',' -参见示例(使用stringstream):

std::string input = "word1,word2,word3";
std::stringstream sstream(input);
std::string word;
while(std::getline(sstream, word, ',')) {
std::cout << word << 'n';
}

最新更新