mercredi 28 décembre 2022

Unexpected char printed in console

int main()
{
  char j[] = "abc";
  print(j);
}

When I define print like this:

void print(const char *cp)
{
  if (cp)
  {
    while (*cp)
    {
      int i = *cp;
      cout << *cp;
      // cout << *cp << endl;
      cp++;
    }
  }
}

The console is something like this (I can not copy the result property, so I use a screenshot) enter image description here The % like character is quite expected

However, when I put the endl the wired % character disappear

void print(const char *cp)
{
  if (cp)
  {
    while (*cp)
    {
      int i = *cp;
      // cout << *cp;
      cout << *cp << endl;
      cp++;
    }
  }
}

enter image description here

Could anyone help explain what happen?

I do not think % is not part of the prompt enter image description here

I change my prompt the a text 'a', and the % still present enter image description here

Aucun commentaire:

Enregistrer un commentaire