【问题标题】:Why is my first program using dev-c++ not working? [closed]为什么我的第一个使用 dev-c++ 的程序不起作用? [关闭]
【发布时间】:2018-02-06 01:29:01
【问题描述】:

我已经安装了 devc++ 并编写了一个基本的 hello world 程序

#include<stdio.h>
int main
{
   cout<<"hello";
   return 0;
}

这是我的跑步。但是在运行代码时出现以下错误

3   1   D:\cpp\helloworld.cpp   [Warning] extended initializer lists only 
                                available with -std=c++11 or -std=gnu++11
4   4   D:\cpp\helloworld.cpp   [Error] 'cout' was not declared in this scope
5   4   D:\cpp\helloworld.cpp   [Error] expected unqualified-id before 
                               'return'
6   1   D:\cpp\helloworld.cpp   [Error] expected declaration before '}' token

请有人帮忙!

【问题讨论】:

  • 合并排序的哪一部分?
  • 你没有为main声明参数。
  • 那里有这么多的hello world程序......怎么可能仍然做错呢?恐怕downvote按钮的工具提示文本适用于您的情况。
  • @trincot 问题可能出在我的 dev c++ 设置上,这就是我希望你调试的。
  • 代码无效,与你的IDE无关。

标签: compiler-errors dev-c++


【解决方案1】:

在您的第一行代码中,您使用#include&lt;stdio.h&gt;,这是一个c preprocessor 指令,但在主函数中您使用cout&lt;&lt;"hello";,这是一个C++ 代码。

对于 C 代码,您需要使用如下代码:

#include <stdio.h>

int main(void)
{
    printf("hello");
    return 0;
}

在 C++ 中(阅读C++ Language),您需要使用类似:

#include <iostream>

int main() 
{
    std::cout << "hello";
    return 0;
}

或者

#include <iostream>
using namespace std;

int main() 
{
    cout << "hello";
    return 0;
}

【讨论】:

    【解决方案2】:

    试试这个:

    #include <iostream>
    
    int main()
    {
    std::cout << "Hello World!\n";
    return 0;
    }
    

    这样的东西在 cplusplus.com 上应该很容易找到 http://www.cplusplus.com/forum/general/49600/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 2013-08-09
      • 1970-01-01
      相关资源
      最近更新 更多