gpt4 book ai didi

c++ - 当我 printf 我的 vector 时,最后的 '%' 是什么?

转载 作者:行者123 更新时间:2023-11-30 01:02:38 24 4
gpt4 key购买 nike

我正在开发一个应用程序,我不知道为什么当我打印我的 vector 时它显示数字“1 2 3 4”,最后它显示一个“%”,如“1 2 3 4 %”

我给你一个代码示例

#include <stdio.h>
#include <vector>
using namespace std;

int n;
vector<int> soldati;

int main(){

scanf ("%d", &n);
for (int i = 1; i <= n; i++){
soldati.push_back(i);
}

for (int i = 0; i < soldati.size(); i++){
printf("%d ", soldati[i]);
}

return 0;
}

here是我运行时显示的内容。

我给了一个链接,因为我不能发布照片。

最佳答案

'%' 来自你的 shell。

您可以在末尾添加 printf("\n") 以明确分隔输出和 shell 提示。

关于c++ - 当我 printf 我的 vector 时,最后的 '%' 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55672913/

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