Vlad Poncea
Vlad Poncea

Reputation: 359

What is the '%' at the end when I printf my vector?

I am working on an app and I don't know why when I am printing my vector it shows the numbers "1 2 3 4" and at the end it shows a "%" like "1 2 3 4 %"

I will give you a code example

#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;
}

And here is what is shows when I run it.

I am giving a link because I can't post photos.

Upvotes: 1

Views: 57

Answers (1)

Anthony Kong
Anthony Kong

Reputation: 40754

'%' comes from your shell.

You can add printf("\n") at the end to clearly seperate your output and your shell prompt.

Upvotes: 5

Related Questions