C++ 此程序不返回任何内容

C++ 此程序不返回任何内容,c++,function,stdstring,C++,Function,Stdstring,我正在尝试编写以下代码,以便它可以返回Hello,World using std::string; using namespace std; std::string hello() { return "Hello, World!"; } int main() { hello(); return 0; } 让代码编译器在0错误的情况下运行,或者运行,然后生成一个银行结果,如所附图片所示。 因此,任何人都可以找出缺少的内容,从而返回所需的结果 您的函数hello()返回字符

我正在尝试编写以下代码,以便它可以返回
Hello,World

using std::string;
using namespace std;
std::string hello()
{
    return "Hello, World!";
}
int main()
{
    hello();
    return 0;
}
让代码编译器在0错误的情况下运行,或者运行,然后生成一个银行结果,如所附图片所示。 因此,任何人都可以找出缺少的内容,从而返回所需的结果

您的函数
hello()
返回字符串“hello,world!”,但在从
main
调用该函数后,您不会对返回的值执行任何操作

你需要输出一些东西!尝试此小修改:

int main ()
{
    std::cout << hello() << std::endl; // So you can avoid "using namespace std!"
    return 0;
}
int main()
{

std::cout你是想打印字符串吗?试试
std::cout About…按照初学者推荐书,这应该告诉你,像
iostream
string
这样的系统头应该使用尖括号
,如
#include
@Blaze在他们的案例中
cout???什么时候应该h函数会“每次”打印什么。我相信我不是唯一一个不明白你想告诉我们什么的人!