#include <iostream>
#include <limits>
int main()
{
int i = 4;
d = 4.0;
string s = "HackerRank";
int a;
double b;
string c;
cin >> a;
cin >> b;
cin >> c;
a = a + i;
b = b + d;
cout << a << endl;
cout << b << endl;
cout << "" + s + c;
return 0;
}
// Declare second integer, double, and String variables.
// Read and save an integer, double, and String to your variables.
// Note: If you have trouble reading the entire string, please go back and review the Tutorial closely.
// Print the sum of both integer variables on a new line.
// Print the sum of the double variables on a new line.
// Concatenate and print the String variables on ne
// The 's' variable above should be printed first.
您错过了添加包含字符串。此外,d变量的声明也不正确。你能用下面的代码试试吗。
#include <iostream>
#include <limits>
#include<string>
int main()
{
int i = 4;
double d = 4.0;
std::string s = "HackerRank";
int a;
double b;
std::string c;
std::cin >> a;
std::cin >> b;
std::cin >> c;
a = a + i;
b = b + d;
std::cout << a << std::endl;
std::cout << b << std::endl;
std::cout << "" + s + c;
return 0;
}
包含的字符串标头操作员的过载<lt;对于std::cout,仅在中定义,因此需要添加字符串标头。
#include <iostream>
#include <limits>
#include <string>
using namespace std;
int main(){
int i = 4;
float d = 4.0;
string s = "HackerRank";
int a;
double b;
string c;
cin >> a;
cin >> b;
cin >> c;
a = a + i;
b = b + d;
cout << a << endl;
cout << b << endl;
cout << "" + s + c<<"n";
return 0;