我最近想用 C++ 制作一个快速模拟器,而不使用 C++(允许使用 C)标准库功能。因此,我使用原始指针数组来存储模拟器的内存。但是,我在将内存类移动到另一个内存类时遇到了读取访问冲突。欢迎所有建议。
内存等级:
#ifndef MEM_HPP
#define MEM_HPP
#include <cstdint>
#include <cstddef>
namespace handle {
using num = std::uint8_t;
using size = std::size_t;
struct memory {
enum { EIGHT_BIT_MAX_MEM = 256, SIXTEEN_BIT_MAX_MEM = 65536 };
constexpr explicit memory(size max_mem) : mem_size(max_mem) {
mem = new num[max_mem];
}
constexpr memory(memory&& other) noexcept {
delete[] mem;
mem = other.mem;
mem_size = other.mem_size;
other.mem = nullptr;
other.mem_size = 0;
}
constexpr memory(const memory& other) = delete;
constexpr ~memory() {
delete[] mem; …Run Code Online (Sandbox Code Playgroud) 在for循环中,我试图使用printf来打印当前的i值.这一行:printf((char *) i);给我运行时错误.为什么是这样?!
以下是一个快速的fizzbuzz解决方案:
void FizzBuzz()
{
for (int i = 0; i < 20; i++)
{
printf((char *)i);
if ((i % 3 == 0) && (i % 5 == 0))
{
printf("FizzBuzz \n");
}
else if (i % 3 == 0)
{
printf("Fizz \n");
}
else if (i % 5 == 0)
{
printf("Buzz \n");
}
else
{
printf("%d\n", i);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我没有编译错误,但它在运行时崩溃,这是我的相关代码,首先是它的结构:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Gas_Station *pgasStationHead = NULL;
typedef struct Gas_Station {
char *name;
double octan95SS;
double octan95FS;
double octan98SS;
double octan98FS;
double gasSoldTotal;
double gasSoldSS;
double gasSoldFS;
struct Gas_Station *pgasStationNext;
struct Client_List *pclientHead;
} Station;
typedef struct Client_List {
char carID[10];
char gasType[3];
double gasAmount;
char serviceType[12];
struct Client_List *pclientNext;
} Client;
Run Code Online (Sandbox Code Playgroud)
之后是有问题的区域:
void CommandsSwitch(FILE *input , FILE *output) {
do {
int i;
char *ptemp , *pfuncNum, *pcarID, *pstationName;
ptemp = fgets(ptemp , 80 …Run Code Online (Sandbox Code Playgroud) 我正在用c ++制作一个简单的蛇游戏.它编译,但不会运行.我在mac上使用netbeans,我以前从来没有这样的问题,所以我认为这是我的代码的问题:
#include <vector>
std::vector<std::vector<int> > snake;//the snake
int main(){
snake[0][0]=0;
}
Run Code Online (Sandbox Code Playgroud)
我认为它可能是2d矢量的问题.
sqlite是一个数据库 - 一个描述符,包含表列表,域列表,字段列表,限制列表(主键和外键),索引列表.我在Delphi XE3的帮助下,在内置组件的帮助下连接到此基础.有一个单独的模块,其中描述了类TTableSpec,TFieldSpec,TConstraintSpec,TConstraintDetSpec,TDomainSpec.这些类对应于上述sqlite的基础记录.在TTableSpec类中有这样的FFields字段:TComponent成为像TFieldSpec这样的对象的所有者,它们也是从基础上卸载的(例如,DBSchema也包含FTables字段是所有表的所有者),并且在TFieldSpec类中有FDomainSpec字段:TDomainSpec.实际上我给出了一个连接错误的类代码
type
TDataTypeId = (DataTypeId_String, DataTypeId_SmallInt, DataTypeId_Integer, DataTypeId_Word,
DataTypeId_Boolean, DataTypeId_Float, DataTypeId_Currency,
DataTypeId_BCD, DataTypeId_FmtBCD, DataTypeId_Date,
DataTypeId_Time, DataTypeId_DateTime, DataTypeId_TimeStamp,
DataTypeId_Bytes, DataTypeId_VarBytes, DataTypeId_Blob,
DataTypeId_Memo, DataTypeId_Graphic, DataTypeId_fmtMemo,
DataTypeId_FixedChar, DataTypeId_WideChar, DataTypeId_LargeInt,
DataTypeId_Array, DataTypeId_FixedWideChar, DataTypeId_WideMemo, DataTypeId_Default);
TDBSchemaSpec=class(Tcomponent)
private
FDomains: TComponent;
FTables : TComponent;
public
procedure Setup();
destructor Destroy; override;
property Domains: TComponent read FDomains;
property Tables : TComponent read FTables;
end;
TDomainSpec = class(TComponent)
private
FName: string;
FDescription: String;
FDataTypeId: TDataTypeId;
FLength: Cardinal;
FCharLength: Cardinal;
FPrecision: Cardinal;
FScale: Cardinal;
FWidth: Word;
FAlign: TAlignSpec; …Run Code Online (Sandbox Code Playgroud) 我希望service在手机完成启动时启动(CheckTime).这似乎有效,但我的应用程序立即崩溃.我收到以下错误" java.lang.RuntimeException: Unable to start receiver com.example.alarmtest.MyReceiver: java.lang.UnsupportedOperationException: Not yet implemented".我试图解决这个问题的尝试都没有成功.我不确定我是否遗漏了一些东西manifest(我对Android的开发还很新).这是我的MyReceiver代码.(出现的log.d)
public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, CheckTime.class);
context.startService(startServiceIntent);
Log.d("evan alarm", "Started on Launch, android autostart");
throw new UnsupportedOperationException("Not yet implemented");
}
}
Run Code Online (Sandbox Code Playgroud)
和CheckTime的代码(这个的日志永远不会出现)
public class CheckTime {
public void loglab(){
Log.d("evan alarm", "We are now in CheckTime");
}
}
Run Code Online (Sandbox Code Playgroud)
最后是清单.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alarmtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk …Run Code Online (Sandbox Code Playgroud) 有些东西是错的,我怀疑它是我的PHP版本,在这台服务器上是5.2; 代码在5.6之前运行,没有任何缺陷......
我已将其调试到以下代码中.但是,我没有收到错误消息..
$standard = array_map( function( $item ) {
return $item['standard_resolution']->url;
}, $images );
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我重做这部分代码,以便在5.2中工作吗?
给定一个整数k,预计会找到分数的值103993/33102,截断到k小数位.所以我的方法如下:
int k ;
scanf("%d",&k);
printf("3");
if(k>0)
printf(".");
long long int num=30;
long long int numer = 1039930;
long long int denom = 33102;
while(k--)
{
long long int bro = numer/denom;
printf("%lld",bro-num);
num=bro;
num*=10;
numer*=10;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果k是20它呈现出怪异的答案....在回路中的任何问题?
http://ideone.com/dndib2
我在多线程中有代码来创建文件夹(如果不存在)
if not os.path.exists(folder): os.makedirs(folder)
Run Code Online (Sandbox Code Playgroud)
我有这样的错误
The folder cannot be created since a file already exists with the same path
Run Code Online (Sandbox Code Playgroud)
我不确定该怎么办,您知道吗?
我正在尝试使用 C 语言做一个简单的计算器。我创建了 4 个函数,分别执行加法、乘法、减法和除法。但是,当我调用主函数中的函数时,它们无法正常工作。即使我输入“+”、“-”、“/”,结果也总是相乘。这里可能有什么问题?
一些单词的翻译要清楚:arti = 加、eksi = 减、carpi = 交叉、bolum = 除法、carpim = 乘法、toplama = 加法、cikartma = 减法、bolme = 除法
谢谢 :)
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int carpim(int numOne, int numTwo, int result){
result = numOne * numTwo;
printf("Sonuc: %d", result);
return 0;
}
int toplama(int numOne, int numTwo, int result){
result = numOne + numTwo;
printf("Sonuc: %d", result);
return 0;
}
int cikartma(int numOne, int numTwo, int result){
result = numOne - numTwo;
printf("Sonuc: %d", result);
return …Run Code Online (Sandbox Code Playgroud)