So I'm trying to type out the code below that insults my brother in law when he types in his name after being prompted, says i love you to my girlfriend, and calls every other person amazing. for some reason every time I input "Jesus Rosa" or "Carly Reyes" it says "You're Amazing" rather than the insult for Jesus or ILY for Carly. Anyone know why?
Also don't be offended by my message to Jesus, we're coding together and he thinks it's hilarious what this code does.
Because that would be reading a c-string into a pre-sized buffer (and you haven't declared maximum characters in your call), not a std::string, which is far more flexible and doesn't need pre-sizing.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string name;
cout << "What is your first and last name?\n";
getline(cin, name);
if (name == "Jesus Rosa")
cout << "You're a spanish piece of shit. \n";
elseif (name == "Carly Reyes")
cout << "I love you. \n";
else
cout << "You're amazing. \n";
}
The cin is of type istream and istream has member getline.
However, it does require two or three arguments, not one.
Furthermore, it does not accept std::string as any of its arguments.
See: https://en.cppreference.com/w/cpp/io/basic_istream/getline