gpt4 book ai didi

c++ - 在 stdout 上格式化 vector 字符串

转载 作者:行者123 更新时间:2023-11-28 07:35:09 26 4
gpt4 key购买 nike

因此,对于我正在为类(class)编写的这个程序,我必须将 vector 字符串格式化为标准输出。我了解如何仅使用带有“printf”函数的字符串来完成此操作,但我不明白如何使用它来完成此操作。

这是我得到的:

void put(vector<string> ngram){
while(!(cin.eof())){ ///experimental. trying to read text in string then output in stdout.
printf(ngram, i);///

最佳答案

好的,我无法从你的问题中读出很多内容,但据我了解,你想将字符串 vector 打印到标准输出!?这将像这样工作:

void put(std::vector<std::string> ngram){
for(int i=0; i<ngram.size(); i++)
{
//for each element in ngram do:
//here you have multiple options:
//I prefer std::cout like this:
std::cout<<ngram.at(i)<<std::endl;
//or if you want to use printf:
printf(ngram.at(i).c_str());
}
//done...
return;
}

这是你想要的吗?

关于c++ - 在 stdout 上格式化 vector 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16888460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com