You are doing
int firstname;
int lastname;
meaning that you want to get an integer value, however you want a string. So, replace the int
with std::string
or string
in your case. Also, remember to #include <string>
to get the string
functionality. After doing this, you should be able to input and return letters. :D
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string firstname;
string lastname;
cout << "My name is " << firstname << lastname;
cin >> firstname >> lastname;
cout << endl;
return 0;
}
Might I add that you generally should not use using namespace std;
as it is considered bad practice, it also is not really necessary, you could just type std::...
. using namespace std
is used if you do not want to type the namespace
name every time, but it's generally better to distinguish between which type of functions you want to use with the same names but in different namspaces. and using '\n'
for a new line as well instead of endl
. This is because endl
takes more time to complete than \n
.