Home > Blockchain >  COUT gives strange number for simple C code
COUT gives strange number for simple C code

Time:06-03

I am trying to add a ASCII asterisk (*) frame around the hello world in a very simple C code. It works but gives this strange number before the frame. Here is my sample code.

#include <iostream>
#include <string>

using namespace std;

int main() {
  cout << "Please enter your name" << endl;
  string name;
  cin >> name;

  string greeting = "Hello, "   name   "!";
  string spaces(greeting.size(), ' ');
  string stars(greeting.size(), '*');

  cout << '**' << stars    <<'**' << endl;
  cout << '* ' << spaces   <<' *' << endl;
  cout << '* ' << greeting << ' *' << endl;
  cout << '**' << stars    <<'**' << endl;
  cout << '* ' << spaces   <<' *' << endl;
 
  return 0;

}

Output

Please enter your name
tester
10794**************10794
10784              8234
10784Hello, tester!8234
10794**************10794
10784              8234
Press any key to continue . . .

Why does it add these numbers before and after the string? Please help. Thanks.

CodePudding user response:

Try double quote, so it looks like this:

cout << "**" << stars    <<"**" << endl;

:-)

  •  Tags:  
  • c
  • Related