标签: compiler-errors

'函数'char*strncpy(char*,const char*,size_t)'的参数太少是什么意思?

我用c ++编写代码,非常简单.

using namespace std;

int main(){
    char cName[30], cFirst[15], cSur[30];


    cout << "Enter your name: " << endl;
    cin.getline(cName, 29);


    for( int i = 0; i < 29; i++)
      if(cName[i] == ' ')
       break;

    strncpy(cFirst, cName, i);


    cFirst[i] = '\0';
    strncpy(cSur,cName + i + 1);
    cSur[i] = '\0';
    cout << cSur << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,程序停止编译,strncpy(cFirst, cName, i);我收到此错误消息"函数'char*strncpy(char*,const char*,size_t)'的参数太少.有人可以解释一下我做错了什么吗?

c++ compiler-errors

-2
推荐指数
1
解决办法
2911
查看次数

Java图形编程绘制图像错误

您好我在将图像绘制到我的框架上时出错.我不确定这里出了什么问题.

我在这里得到以下错误.

Java: 77: cannot find symbol
symbol: variable image
location: class DrawComponent
g.drawImage(image, 0, 0, null);


class DrawComponent extends JComponent {
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        // draw a circle with the same center
        double centerX = 250;
        double centerY = 180;
        double radius = 20;

        Ellipse2D circle = new Ellipse2D.Double();
        circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius);
        g2.setPaint(Color.RED);
        g2.fill(circle);
        g2.draw(circle);

        String filename = "SydneyOperaHouse.jpeg";
        try{
            Image image = ImageIO.read(new File(filename));
        }catch(IOException ex){ …
Run Code Online (Sandbox Code Playgroud)

java user-interface swing scope compiler-errors

-2
推荐指数
1
解决办法
1805
查看次数

C#程序错误

这是我的代码:

using System.Runtime.InteropServices;
using System;

class Program
{
    static void Main(string[] args)
    {
        int processId;
        Console.WriteLine(PlatformInvokeTest.LaunchApp(@"1f0f1577-bc5a-4c10-9a06-f939dc76a130_9tzsbvskx44gy!App", out processId));
        Console.WriteLine(processId);    
    }
}

public class PlatformInvokeTest
{
    [DllImport("MAF32.dll")]
    public static extern int LaunchApp(
        [In, MarshalAs(UnmanagedType.LPWStr)]string processIdentifier,
        [Out, MarshalAs(UnmanagedType.U4)] out int processId);
}
Run Code Online (Sandbox Code Playgroud)

即使我已经包含"使用系统;",我仍然会收到以下错误:

The name 'Console' does not exist in the current context.

有人可以帮我解决这个问题吗?

c# compiler-errors

-2
推荐指数
1
解决办法
133
查看次数

Perl:elsif,Python:elif,C/CPP/Java:否则如果

这是代码在Perl上给我错误.


...
else if (exists($framename{$presFrame}) && (($framename{$presFrame}) < = $j))
...
Run Code Online (Sandbox Code Playgroud)

framename是一个哈希,presFrame是一个关键存在于framename

编辑:

在正确答案中提到的Perl中实现if/else语法有点不同.

perl if-statement compiler-errors key syntax-error

-2
推荐指数
1
解决办法
155
查看次数

错误LNK1169:找到一个或多个多重定义的符号

我正在制作Avl树项目,但得到2个构建错误,即

error LNK1169: one or more multiply defined symbols found
error LNK2005: "struct avl_node * root" (?root@@3PAUavl_node@@A) already defined in AVL.obj 
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#include "AVL.h"

int main()
{
  AVL obj;
  char pn[30],fn[30],add[20],di[15],dn[30];
  int id,age,nic;
  int ch;
  cout<<"Want To Build BST On Basis Of:"<<endl
    <<"1.NIC"<<endl
    <<"2.ID"<<endl;
  cout<<"Enter Your Choice:";
  cin>>ch;
  switch(ch)
  {
    case 1:
      do{
        cout<<"Patients Database"<<endl
          <<"1.Enter New Record"<<endl
          <<"2.Search Record"<<endl
          <<"3.Delete Record"<<endl
          <<"4.Show Record"<<endl
          <<"5.Exit"<<endl;
        cout<<"What Do You Want To Do:";
        cin>>ch;
        switch(ch)
        {
          case 1: cout<<"Enter Patient ID:";
                  cin>>id; …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors

-2
推荐指数
1
解决办法
3971
查看次数

C++编译错误

首先,这是我的C++源代码:

#include <iostream>
using namespace std;

void number(int x){
    cout << "Number is: " << x << endl;
}

int main(){
    cin >> int x;
    number(x);
    return(0);
}
Run Code Online (Sandbox Code Playgroud)

编译后,我收到以下错误:

  • file.cpp:在函数'int main()'中:
  • file.cpp:9:9:错误:预期在'int'之前表达primary
  • file.cpp:9:9:错误:预期';' 'int'之前
  • file.cpp:10:9:错误:在此范围内未声明"x"

我在CodeBlocks中成功编译并运行它,但在Ubuntu下使用gccg ++会失败.

c++ compiler-errors

-2
推荐指数
1
解决办法
248
查看次数

C# - 为什么我不能在另一个类中更改我的int变量?

好的,所以我有以下变量:

    public static int cookieCount = 0;
    public static int cursorCount = 0;
    public static int granCount = 0;
    public static int farmCount = 0;
    public static int mineCount = 0;
    public static int shipCount = 0;
    public static int alcCount = 0;
    public static int portalCount = 0;
    public static int timeCount = 0;

    public static int clickGain = 1;
    public static int cursorGain = 1;
    public static int granGain = 5;
    public static int farmGain = 10;
    public …
Run Code Online (Sandbox Code Playgroud)

c# compiler-errors global-variables

-2
推荐指数
1
解决办法
131
查看次数

错误:期待';' 在括号之前

嘿伙计们,我的大脑已经正式进入所有这些项目,因为我似乎可以找出这个相对简单的错误.

所以我遇到的问题是它要求我在curli括号之前添加一个分号,这里是它发生的代码段.

bool IsAlive(int row, int col){
        return true;
    }
Run Code Online (Sandbox Code Playgroud)

它是在'col)之后问我一个分号.这是完整的代码

#include <iostream>
#include <windows.h>

#define NumGen 1
#define NumRows 13
#define NumCol 13

using namespace std;


void main()
{
    const int NumModRows=NumRows+2;
    const int NumModCol=NumCol+2;
    int grid[NumGen][NumModRows][NumModCol]={0};
    grid[NumGen][0][0]=5;
    //cout<<"Hey this is number "<<grid[NumGen][0][0]<<endl;
    //int upLeft=-1, upMid=-1, upRight=-1, left=-1, right=-1, botLeft=-1, botMid=-1, botRight=-1;
    //cout<<"All: "<<upLeft<<", "<<upMid<<", "<<upRight<<", "<<left<<", "<<right<<", "<<botLeft<<", "<<botMid<<", "<<botRight<<endl<<endl;
    //get input from user

    int rowInput;
    int colInput;
    int numInputs;
    cout<<"how many inputs will be inserted in the …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors syntax-error

-2
推荐指数
1
解决办法
122
查看次数

在与负数进行比较时,在程序中迷路'\ 342'

每当我与负数GCC进行比较时,我都会看到:

error: stray '\342' in program
   if ( -4 < ÔÇô3 ) return 1;
   ^
compilation terminated due to -Wfatal-errors.
Run Code Online (Sandbox Code Playgroud)

码:

int main() {
  if ( -4 < –3 ) return 1;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ gcc compiler-errors

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

Java调用Python(期望的类,接口或枚举)

我创建了一个调用python脚本的java程序

Runtime r = Runtime.getRuntime();
Process p = r.exec("cmd /c python ps.py sender-ip=10.10.10.10");
Run Code Online (Sandbox Code Playgroud)

当我编译时,我得到错误:

call_py.java:1: error: class, interface, or enum expected
Runtime r = Runtime.getRuntime();
^
call_py.java:2: error: class, interface, or enum expected
Process p = r.exec("cmd /c python ps.py sender-ip=10.10.10.10");
^
2 errors
Run Code Online (Sandbox Code Playgroud)

java程序和python脚本都在同一目录下,我该如何解决这个问题呢?

python java compiler-errors compilation

-2
推荐指数
1
解决办法
102
查看次数