我写了以下程序
#include <stdio.h>
main()
{
int i = 2;
float c = 4.5;
printf("%d\n",c);
printf("%f\n",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
虽然我知道这是错误的做法,当我运行程序时,我得到了答案
0
4.500000
Run Code Online (Sandbox Code Playgroud)
但是当我用这种方式交换printf语句时
#include <stdio.h>
main()
{
int i = 2;
float c = 4.5;
printf("%f\n",i);
printf("%d\n",c);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是
0.000000
0
Run Code Online (Sandbox Code Playgroud)
我无法理解发生了什么,任何人都会解释我.
C++代码是:
unsigned short* ui=(unsigned short*)&buf[110];
CountDev=ui[0];
Run Code Online (Sandbox Code Playgroud)
buf byte[]和CountDev是unsigned int
(BCB6编译器x86)
我的尝试是:F#
...CountDev = System.BitConverter.ToInt32( [| arrayRead.[110]; arrayRead.[111] |] , 0 )
Run Code Online (Sandbox Code Playgroud)
C#
...CountDev = System.BitConverter.ToInt32( [arrayRead[110]; arrayRead[111]] , 0 )
Run Code Online (Sandbox Code Playgroud)
但严重的是我无法确定.检查我的尝试,告诉我,如果我做错了请.
我有以下代码,但它会导致异常.如果没有itoa"游戏",我认为没有问题.TextOutA是因为我使用winapi.
char* p1 = new char[2];
itoa(10,p1,10);
TextOutA(hDC,5, currenty,p1,2);
delete[] p1;
Run Code Online (Sandbox Code Playgroud) 所以我刚接受了面试,他们给了我一份他们希望我事先处理的任务清单.我完成了除了一个以外的所有任务,并且想知道是否有人能够对这个问题有所了解.
问题就是这样的
我完成了任务1-3,但是在问题4上被困了.我在过去的继承工作经历中并没有做太多的事情,这个问题对我来说似乎有点模糊.我向雇主解释了这一点,他们看起来还不错,但没有告诉我应该怎么做.它现在一直困扰着我,我想知道它是如何完成的.
我试图在FLOAT课堂上重载(*,+, - ,/,=)opertors .我写了这堂课:
class FLOAT{
private:
float x;
public:
FLOAT(){ x=0.0; }
void setFloat(float f) { x=f; }
void operator+(FLOAT obj) {x=x+obj.x; };
void operator-(FLOAT obj) {x=x-obj.x; };
void operator*(FLOAT obj) {x=x*obj.x; };
void operator/(FLOAT obj) {x=x/obj.x; };
FLOAT& operator=(const FLOAT& obj) {this->x=obj.x; return *this; };
};
Run Code Online (Sandbox Code Playgroud)
我用它如下:
int main() {
FLOAT f,f2,f3;
f.setFloat(4);
f2.setFloat(5);
f3=f+f2;// here is the problem!
system("pause");//to pause console screen
return 0;
}
Run Code Online (Sandbox Code Playgroud)
f3=f+f2似乎不对.我能做什么?
我不熟悉backbone.js下面是我的代码我需要的是在backbone.js中需要的语法/代码,以便在我的表的每一行中产生唯一的id,这样当删除delete时我从表中删除该特定的行.
$(function(){
var Person = Backbone.Model.extend({
id: 0,
name: 'default name',
age: 100
});
var PersonCollection = Backbone.Collection.extend({
model: Person
});
var PersonView = Backbone.View.extend({
el: $('#personEL'),
events:
{
"click #login-btn" : "loginClick"
},
loginClick: function()
{
var name = $('#name').val();
var age = $('#age').val();
var newPerson = new Person({id: 1,name: name, age : age});
this.personCollection.add(newPerson);
var showit = new zview({model: newPerson});
},
initialize: function(){
this.personCollection = new PersonCollection();
this.render();
},
render: function()
{
var template = _.template( $("#personInputTemplate").html(), {} …Run Code Online (Sandbox Code Playgroud) 我正在研究一个简单的自上而下的射击游戏,并希望将我的船只移到一个单独的ShipManager类,在那里我可以从一个位置管理所有这些.但是,在启动时,我的playerShip上出现了一个链接器错误:
错误LNK2001:未解析的外部符号"public:static class Ship*ShipManager :: playerShip"
ShipManager.h如下所示:
class Ship;
class ShipManager
{
public:
static Ship* playerShip;
};
Run Code Online (Sandbox Code Playgroud)
我在ShipManager .cpp中什么都没有.我错过了什么?我使用此代码的唯一其他地方是在我的游戏类中,我实际上正在调用ShipManager :: playerShip,我没有在那里得到任何错误.
我在我的game.cpp中包含"ShipManager.h",所以应该找到它吗?我有一种感觉,我在这堂课中忘记了一些简单的事情.
我正在尝试尽可能多地使用前向声明来最小化编译时间.我注意到当我转发声明一个使用类似std :: vector的类作为成员对象的类时(这里的例子):
class myTypeA
class A
{
A(){};
~A(){};
std::vector<myTypeA > getTypeA();
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
microsoft visual studio 9.0\vc\include\vector(1112) : error C2036: 'myTypeA *' : unknown size
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(1102) : while compiling class template member function 'bool std::vector<_Ty>::_Buy(unsigned int)'
1> with
1> [
1> _Ty=myTypeA
1> ]
1> d:\cpp\A.h(15) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=myTypeA
1> ]
Run Code Online (Sandbox Code Playgroud)
当我使用#include"myTypeA.h"时,这工作正常,为什么?
当我尝试使用AVR studio 4调试一小段代码时出现此错误:
Build failed... No build tools defined.
Run Code Online (Sandbox Code Playgroud)
有人可以给我一些建议吗?
我提到了两个可靠的信息来源,两者似乎对同一事物有不同的定义:
http://www.cplusplus.com/reference/clibr%E2%80%A6
http://www.ocf.berkeley.edu/~pad/tigcc/doc/html/stdio_fputchar.html
第一个来源说的putchar()是一个函数,getchar()但是在第二个链接中它表示putchar()是一个宏.我的书说getchar()是一个宏.哪个是对的?