我试图得到这个问题,但无法理解为什么它给出编译时错误我的代码是:
#include<stdio.h>
static struct student
{
int a;
int b;
int c;
int d;
}s1={6,7,8,9},s2={4,3,2,1},s3;
void main()
{
s3=s1+s2;
clrscr();
printf("%d %d %d %d",s3.a,s3.b,s3.c,s3.d);
getch();
}
Run Code Online (Sandbox Code Playgroud) 这段代码有什么问题,在你问我之前用youtube视频和简短的教程做了这一切.非常感谢有人可以帮我编码,在这种情况下只需要我的Skype,我会加你,我需要这样做!:).
在第253行左右,它说需要"预期的缩进块"我真的不知道该怎么做.
import pygame, sys, time, random, Globals
from pygame.locals import *
pygame.init()
pygame.mixer.init(frequency=22050, size=-16, channels=10, buffer=4096)
#Classes
class MenuButton(pygame.sprite.Sprite):
def __init__(self, image, image_dem, x, y):
self.image = pygame.image.load(image[0]).convert_alpha()
self.image_over = pygame.image.load(image[1]).convert_alpha()
self.image_dem = image_dem
self.x = x
self.y = y
self.rect = pygame.Rect(self.x, self.y, self.image_dem[0], self.image_dem[1])
def setXY(x, y):
self.x = x
self.y = y
def setImage(image, dem):
self.image = pygame.image.load(image[0]).convert_alpha()
self.image_over = pygame.image.load(image[1]).convert_alpha()
self.image_dem = dem
class Sprite(pygame.sprite.Sprite):
def __init__(self, image, image_dem, x, y):
self.image = pygame.image.load(image).convert_alpha()
self.image_dem …Run Code Online (Sandbox Code Playgroud) 当我尝试编译此代码时
using namespace std;
namespace asf{
inline int operator|(int);
}
asf::operator|(int x){
return (x>1)?x*operator|(x-1):1;
}
int main(){
cout<<5|;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
[Error] 'int asf::operator|(int)' must have an argument of class or enumerated type
[Error] ISO C++ forbids declaration of 'operator|' with no type [-fpermissive]
[Error] 'int asf::operator|(int)' should have been declared inside 'asf'
[Error] 'int asf::operator|(int)' must have an argument of class or enumerated type
In function 'int main()':
[Error] expected primary-expression before ';' token
Run Code Online (Sandbox Code Playgroud)
怎么了?请帮忙.
好的,所以输入是一个字符串.当我尝试编译以下代码时,我得到了
c.cpp:42:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
Run Code Online (Sandbox Code Playgroud)
为什么?
if(input[i] != ' ')
{
char s = input[i];
if(s == "+")
{
...
}
}
Run Code Online (Sandbox Code Playgroud) 我在程序中创建了一个快速方法,使用距离公式计算两点之间的距离,这里是代码:
#include <iostream>
#include <cmath>
using namespace std;
int distanceFormula(int x1, int y1, int x2, int y2) {
double d = sqrt((x1-x2)^2(y1-y2)^2);
return d;
}
Run Code Online (Sandbox Code Playgroud)
它给我一个编译器错误,我声明"d"变量说"错误:表达式不能用作函数".这是什么意思?我做错了什么?
我有一个包含枚举的C头文件
typedef enum {leaf, operator} my_type;
Run Code Online (Sandbox Code Playgroud)
现在当我尝试在我的C++程序中包含此标题时,我得到错误"'运算符'之前的预期标识符"
我怎么能摆脱它.
import java.util.Scanner;
import java.util.Random;
public class random {
public static void main(String[] args) {
System.out.println("===== CS302 TOOL BOX =====");
System.out.println("T > COIN TOSS SIMULATOR");
System.out.println("G > GRADE ESTIMATOR");
System.out.println("C > COLOR CHALLENGE");
System.out.println("Q > QUIT");
System.out.print("Type code letter for your choices: ");
String Menuchoices = "TGCQ";
String initial_input = scanner.next();
String code_choice = initial_input.toUpperCase();
boolean code_letter;
if (code_choice.equals(Menuchoices.substring(0,1))
||code_choice.equals(Menuchoices.substring(1,2))
||code_choice.equals(Menuchoices.substring(2,3))
||code_choice.equals(Menuchoices.substring(3,4)));
{System.out.println("success");}
else {System.out.println("Failure");}
}
}
Run Code Online (Sandbox Code Playgroud)
Eclipse不会允许我把这个声明放进去.任何想法为什么?
我在Java中运用思考方面遇到了问题.这是代码(这是练习的解决方案).
// object/StorageTest.java
// TIJ4 Chapter Object, Exercise 6, page 90
// Write a program that includes and calls the storage() method defined as a
// code fragment in this chapter.
public class StorageTest {
public static void main(String[] args) {
class StoreStuff {
int storage(String s) {
return s.length() * 2;
}
}
StoreStuff x = new StoreStuff();
System.out.println(x.storage("hi"));
}
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时,我有这个错误:
C:\ Users\Ivan\Desktop> javac StorageTest.java StorageTest.java:5:错误:找不到符号返回(s.lenght()*2); ^符号:方法lenght()位置:类型为String 1的变量s错误
我不明白为什么会这样.
struct B {
int b;
B(int i = 0) : b(i) {}; // constructor
};
struct D : B {
int d;
};
int main () {
D obj = {1}; // <-- error
// D obj {1}; // <-- error (different)
}
Run Code Online (Sandbox Code Playgroud)
上面的代码没有编译,并给出:
error: could not convert ‘{1}’ from ‘<brace-enclosed initializer list>’ to ‘D’
Run Code Online (Sandbox Code Playgroud)
即使我删除了"构造函数"行也是如此.如果我删除=符号,即D obj {1};它然后给出如下:
error: no matching function for call to ‘D::D(<brace-enclosed initializer list>)’
Run Code Online (Sandbox Code Playgroud)
解决此类问题的正确语法是什么?
为什么这一小段代码在第6行和第10行(for循环)中给出了非法的类型错误启动....我找不到任何不匹配的大括号......
class StackDemo{
final int size = 10;
Stack s = new Stack(size);
//Push charecters into the stack
for(int i=0; i<size; i++){
s.push((char)'A'+i);
}
//pop the stack untill its empty
for(int i=0; i<size; i++){
System.out.println("Pooped element "+i+" is "+ s.pop());
}
}
Run Code Online (Sandbox Code Playgroud)
我实现了Stack类,
compiler-errors ×10
c++ ×5
java ×3
c ×2
c++11 ×1
char ×1
compilation ×1
if-statement ×1
indentation ×1
inheritance ×1
namespaces ×1
pygame ×1
python ×1
stack ×1
string ×1