无法在 C++ 中使用 cout 函数

发布于 2024-12-22 05:24:36 字数 290 浏览 3 评论 0 原文

我是 C++ 新手,我无法运行我的第一个 C++ 程序,代码是

     #include <iostream.h>
   void main() 
   {
     cout>>"Hello world!">>endl;
   }

但未能在控制台上打印 "Hello world!" ,我对这个问题感到困惑小时,配置似乎没有错误,我使用的是 Visual C++ 2010 Express,它是基本控制台项目格式,有人可以帮助我吗?

I'm a novice on C++, and I failed to run my first C++ program, the code is

     #include <iostream.h>
   void main() 
   {
     cout>>"Hello world!">>endl;
   }

but it failed to print "Hello world!" on the console, I'm confused on this issue for hours, and there seems not wrong with the configuration, I'm using Visual C++ 2010 Express and it's the basic console project format, can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

两人的回忆 2024-12-29 05:24:36

你的方向错了。

cout << "Hello world!" << endl;

<< 视为将数据推入 cout(即输出)。

相反,您可以使用 >>cin 将数据从输入推送到变量中。

You have your direction wrong.

cout << "Hello world!" << endl;

Think of << as pushing data into cout, i.e. the output.

Inversely, you use >> with cin to push data into a variable, from input.

掩饰不了的爱 2024-12-29 05:24:36

您应该启用编译器上的所有警告和调试信息。

“双箭头”应该指向流,因为它是输出,所以你可能应该说

 std::cout << "Hello World!" << std::endl;

You should enable all warnings and debugging information on your compiler.

The "double arrow" should go to the stream since it is an output, so you should probably say

 std::cout << "Hello World!" << std::endl;
染柒℉ 2024-12-29 05:24:36

1.

#include 已过时。
Thinking in C++ 说它相当于

#include <iostream>
using namespace std;

但后者是流行的。

2.

正如其他人所说,你应该使用
cout<<“世界你好!”<

3.
使用 ; 而不是

为了清楚起见,我猜 2 是你的主要问题,3 可能是一个拼写错误,而 1 是一个建议

1.

#include <iostream.h> is outdated.
thinking in C++ says it is equivalent to

#include <iostream>
using namespace std;

But the latter is the prevailing one.

2.

as stated by others, you should use
cout<<"Hello world!"<<endl

3.
use ; instead of

To be clear, I guess 2 is your major problem and 3 maybe a typo while 1 is an advice

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文