What is wrong with this piece of code?

Advertisement

#include <iostream>
char str[20]’
int main(){
std::cout << “What’s your name? “;
str << std::cin
std::cout << “Hello, ” << str;
return 0;
}

  • The main function is supposed to have a void return type.
  • std::cin and std::cout are invalid. The correct names for the character input and output streams are cin and cout.
  • The address of str is supposed to be used. That is &str instead of str.
  • The input operator flow is inverted. it should start from std::cin and then flow (>>) into str.
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Leave a Comment

Share via
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.