我在头文件和源文件中有此代码。这是代码的小片段。这是来自.cpp文件。
int sample(Cdf* cdf)
{
//double RandomUniform();
double r = RandomUniform(); //code that is causing the error
for (int j = 0; j < cdf->n; j++)
if (r < cdf->vals[j])
return cdf->ids[j];
// return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是从.c文件:
double RandomUniform(void)
{
double uni;
/* Make sure the initialisation routine has been called */
if (!test)
RandomInitialise(1802,9373);
uni = u[i97-1] - u[j97-1];
if (uni <= 0.0)
uni++;
u[i97-1] = uni;
i97--;
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是从我的头文件
void RandomInitialise(int,int);
double …Run Code Online (Sandbox Code Playgroud) 我在尝试编译时遇到标题错误.
#include <iostream>
using namespace std;
int chance()
{
return rand()%11;
}
int main()
{
if (chance > 5)
cout << "You win." << endl;
else
cout << "You lose." << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我的完整代码,我试图让它输出你赢了或输了,50-50
当我编译我的Linux程序时,我收到此错误:
error: storage class specifiers invalid for parameter declarations
Run Code Online (Sandbox Code Playgroud)
这只发生在Linux上,因为它可以很好地编译Windows.代码行是:
int Start(static const char* m_vertexshader, static const char* m_fragmentshader);
Run Code Online (Sandbox Code Playgroud)
如果您需要任何细节或信息,请使用GNU C编译器(g ++)
大家好,并提前感谢任何帮助,这是情况:
#define N 12
[..]
char vect[N][2];
char strng[2];
[..]
vect[i][0]=strng[2]; //this two lines are in a simple for cycle
vect[i][2]=strng[0];
Run Code Online (Sandbox Code Playgroud)
现在,如果string[2]我有"c 2",我所期望的vect[i][0]就是'2'和vect[i][1] 'c'.
我使用code::blocks和观看vect我有"2@",但它也可以"2À".
你能帮助我吗?我哪里错了?
我得到一个巨大的错误列表.它指向包含的iostream和术语"运算符"的每个实例这种情况发生在我编译比简单的"Hello World"更复杂的任何时候

这是我的代码:
#include <iostream>
using namespace std;
int main()
{
void *x;
int arr[10];
x = arr;
*x = 23; //This is where I get the error
}
Run Code Online (Sandbox Code Playgroud)
如您所见,代码非常简单.它只是创建一个void指针x,它指向数组'arr'的内存地址,并将整数23放入该内存地址.但是当我编译它时,我收到错误消息"'void*'不是指向对象的指针类型".当我使用'int'指针而不是void指针然后编译它时,我没有得到任何错误或警告.我想知道为什么我会收到这个错误.
谢谢.
最近我在我的代码块编程,我做了一个小程序只是为了C的爱好.
char littleString[1];
fflush( stdin );
scanf( "%s", littleString );
printf( "\n%s", littleString);
Run Code Online (Sandbox Code Playgroud)
如果我创建了一个字符串,为什么CodeBlocks允许我保存13个字符?
在代码块中构建或编译器选项中没有C++ 17选项,只有C++ 14如何在代码块中启用它,以便编码工具和编译器都支持它?
我是C语言中的新结构,但据我所知,我的代码是"正确的".我正在使用Codeblocks,但我也在DEV C++中编译它,我得到了同样的错误
#include <stdio.h>
#include <stdlib.h>
struct film{
int year;
char title[30];
char director[30];
char main_char[30];
} ;
int main ()
{
film venom={ 2018, "Venom", "Ruben Fleischer", "Tom Hardy" };
printf("Year: %d\n", venom.year);
printf("Title: %s\n", venom.title);
printf("Director: %s\n", venom.director);
printf("Main Character: %s\n", venom.main_char);
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
所以,我有一个程序使用图形模式[ graphics.h]库...我想初始化图形,所以我会这样做,所以自然地这样做:
initgraph(graphics_driver,graphics_mode,"") ;
Run Code Online (Sandbox Code Playgroud)
当我编译上面的代码时,它会给出错误"ISO C++禁止将字符串常量转换为char*"
我知道一个解决方法:
char c_array[] = "" ;
initgraph(graphics_driver,graphics_mode,c_array) ;
Run Code Online (Sandbox Code Playgroud)
上面编译得很好......这对于像...这样的函数是可以的initgraph(),因为我只会调用一次.但是,我想使用这样的outtextxy()函数(因为我在我的程序中多次调用它):
outtextxy(0,0,"Test") ;
Run Code Online (Sandbox Code Playgroud)
因为为所有不同的outtextxy()函数声明一个数组只会浪费空间.
那么,有没有办法使用上面没有数组或任何额外的变量?
PS:我在安装graphics.h库并配置所有链接器选项后使用代码块.等等...
谢谢,再见,塞缪尔