标签: dev-c++

如何解决"声明朋友时必须使用的类"错误?

class two;
class one
{
    int a;
    public:
        one()
        {
            a = 8;
        }
    friend two;
};

class two
{
    public:
        two() { }
        two(one i)
        {
            cout << i.a;
        }
};

int main()
{
    one o;
    two t(o);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

我从Dev-C++得到这个错误:

a class-key must be used when declaring a friend
Run Code Online (Sandbox Code Playgroud)

但是使用Microsoft Visual C++编译器编译时运行正常.

c++ dev-c++ visual-c++ friend-function

4
推荐指数
2
解决办法
2812
查看次数

我的c程序打印"内存不足" - 错误,但有很多可用的内存空间

我的程序返回内存错误,而不使用超过1 MB.我在dev-cpp编译器中编写C语言.原来的程序太大了,无法放在这里.这个非常简单的程序适合我:

int main(){int a[520076]; return 0;}

并返回值0.但是,这个:

int main(){int a[520077]; return 0;}

不起作用,原因是记忆.我使用的是Windows 8,但Windows 7中出现了同样的问题.看起来系统对进程可以使用的内存空间进行了限制.也许dev-cpp还可以建立边界吗?

c memory dev-c++

4
推荐指数
1
解决办法
179
查看次数

在switch case语句中,它表示"重复案例值"出现错误.谁知道为什么?

我正在研究一个石头剪刀程序,但这次计算机选择摇滚一半时间,剪刀三分之一时间,纸张只有六分之一时间.我这样做的方式是我列举了六种可能的计算机选择值:

enum choicec {rock1, rock2, rock3, scissors1, scissors2, paper};
choicec computer;
Run Code Online (Sandbox Code Playgroud)

但是,在计算机做出选择之后,我必须将这些枚举值转换为摇滚,纸张或剪刀.我使用switch-case语句做到了这一点:

switch(computer) {
        case rock1 || rock2 || rock3:
            c = 1;
            break;
        case scissors1 || scissors2: //ERROR!
            c = 3;
            break;
        case paper:
            c = 2;
            break;
    }
Run Code Online (Sandbox Code Playgroud)

一个是摇滚,两个是纸,三个是剪刀.但是,在我作为注释写入错误的行上,它给了我这个错误:[错误]重复的案例值.

我不知道为什么.有任何想法吗?

c++ dev-c++ switch-statement

4
推荐指数
2
解决办法
2万
查看次数

无限循环不能在C中工​​作

我正在读Ivor Horton的Beginning C. 无论如何我无限期地for打印我的printf声明两次,然后再继续.我确定我做错了但是我从书中复制了代码.如果重要的话,我正在使用Dev-C++.这是代码......谢谢

#include <stdio.h>
#include <ctype.h>  // For tolower() function  //

int main(void)
{
char answer = 'N';
double total = 0.0;  // Total of values entered //
double value = 0.0;  // Value entered //
int count = 0;

printf("This program calculates the average of"
                       " any number of values.");
for( ;; )
{
    printf("\nEnter a value: ");
    scanf("%lf", &value);
    total+=value;
    ++count;

    printf("Do you want to enter another value? (Y or N): "); …
Run Code Online (Sandbox Code Playgroud)

c dev-c++

4
推荐指数
1
解决办法
1106
查看次数

为什么这个按位运算返回30而不是384?

我正在使用Dev-C++编译器.这个程序应该打印30但是它的打印384.

#include <stdio.h>

int main() {
    int n = 3;
    int ans;

    ans = n<<3 + n<<1;
    printf("%d", ans);

    getch();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c dev-c++ bitwise-operators

4
推荐指数
1
解决办法
95
查看次数

如何将mingw-w64和MSYS2与任何IDE(例如eclipse或代码块)一起使用?

  1. 在这里安装msys2 。
  2. 我从这里下载 i686-5.3.0-release-posix-dwarf-rt_v4-rev0
  3. 设置msys2-i686-20160205.exe后,将i686-5.3.0-release-posix-dwarf-rt_v4-rev0提取到C:\ msys32中
  4. 最后我从开始菜单运行MinGW-w64 Win32 Shell并分别运行以下命令:

    • 吃豆人-Sy吃豆人

    • 吃豆人

    • 吃豆人

  5. 在PATH中添加C:\ msys32 \ mingw32 \ bin

我的问题:

  1. 可以在任何IDE中使用mingw-w64,这是真的吗?
  2. MinGW-w64 Win32 ShellMSYS2 Shell有什么区别?

提前致谢。

eclipse codeblocks dev-c++ mingw-w64 msys2

4
推荐指数
1
解决办法
2318
查看次数

开发 无法执行.exe错误193:%1不是有效的win32应用程序

所以我试图像往常一样测试运行我的dev c ++并且它说无法执行location/name.exe错误193:%1不是有效的win 32应用程序.我还没有将编译器用于任何复杂的事情.

#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
{
    int r      = 3;

    float area = PI*pow(r,2);

    printf("the area of the circle is %f",area);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Dev c ++ GCC(MinGW)编译器.

它编译正确,但当我尝试运行时,它会收到此错误消息

无法执行"C:\ Users\SIM JONES NIGL TD\Desktop\c language\areaofcircle2.exe":错误193:%1不是有效的Win32应用程序.

按任意键继续

c c++ dev-c++

4
推荐指数
1
解决办法
2万
查看次数

auto 关键字在 Dev C++ 中不起作用

这是我编写的代码,用于查看auto关键字如何工作,但它没有在 Dev C++ 中编译并给出以下警告: [警告] C++11 auto only available with -std=c++11 or -std=gnu ++11 如何克服这个故障并按照警告的指示去做?

#include<iostream>
#include<string>
#include<vector>

using namespace std;
int main()
{
    std::vector<auto> v={2,-1,4,6,7};
    auto beg = v.begin();
    while (beg != v.end())
    {
        ++beg;
        cout<<beg;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors vector dev-c++ auto

4
推荐指数
1
解决办法
7464
查看次数

变量“std::ofstream outfile”具有初始值设定项,但类型不完整

我已经制作了一个关于此的程序,该程序使用Dev C++CPP创建了很多文件,这个程序也使用 Dev C++ 但现在它显示错误。我的专业是创建模板,但它显示.codeHTMLerror

这是我的一些code

#include <iostream>
using std::cout;
using std::cin;
using std::ofstream;
using std::endl;

void HelloWorld() {
    ofstream outfile ("html1.html");

    outfile << "<html> " << endl;
    outfile << "   <head> <title> Template Hello World </title> </head>" << endl;
    outfile << "   <body> <h1> Hello World! </h1> </body> " << endl;
    outfile << "</html> " << endl;
    outfile << "// Template HTML 2018 " << endl;
    cout << "Created Succesfuly! Directory: …
Run Code Online (Sandbox Code Playgroud)

c++ dev-c++

4
推荐指数
1
解决办法
5945
查看次数

C++读取每行中具有未知整数数的固定行数

我正在尝试读取数据并解决简单问题,数据:

3               - number of lines to read in
1 1
2 2 2
3 4 
Run Code Online (Sandbox Code Playgroud)

在输入每一行之后,我想获得输入数量的总和,但每行中的整数数量是未知的.使用上面的数据后,屏幕应如下所示:

3               
1 1
Sum: 2
2 2 2
Sum: 6
3 4 
Sum: 7
Run Code Online (Sandbox Code Playgroud)

但是根据我的算法,我得到了输出:

3
1 1
Sum: 1
2 2 2
Sum: 4
3 4
Sum: 3
Run Code Online (Sandbox Code Playgroud)

我已经写代码,但它不能正常工作(如上):
我提高了我的代码,并知道它正常工作,不附带任何条件等,适当的代码如下:

#include<iostream>
using namespace std;
int main()
{
    int x;
    int t, sum;
    cin >> t;

    for(int i=0; i<t; i++) {
        sum=0;
        while(true)
        {
            cin >> x;
            sum = sum + x; …
Run Code Online (Sandbox Code Playgroud)

c++ dev-c++

3
推荐指数
1
解决办法
1232
查看次数