我写了这样的代码:
#include<iostream>
using namespace std;
int main()
{
cout<<static_cast<float>(5/9)*9;
cout<<static_cast<float>(5)/9*9;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
预期产量:55
原始输出:05
为什么第一个静态转换语句变成 0 ?
some_vector.push_back(make_shared<ClassName>());
some_vector.emplace_back(make_shared<ClassName>());
Run Code Online (Sandbox Code Playgroud)
我想检查一下我的理解是否正确,对于make_shared返回对象的所有其他函数,这两个调用是相同的。这里make_shared将创建一个新的shared_ptr,然后这个指针都将在被转移到容器中push_back和emplace_back。这是正确的,还是会有一些区别?
我有一个关于反向圆周运动的查询.我有下面的代码.壳体1是顺时针圆周运动,壳体2是逆时针方向.情况1和2之间的切换是通过用户触摸完成的.当它从顺时针切换到逆时针它使用相同的值的sin()和cos()是timer/1.5.这导致逆时针运动从我星球上的不同位置开始.我想计算我的计时器所需的值,以便逆时针运动从顺时针运动期间停止的位置开始,从而具有平滑过渡.当我的思绪陷入困境时,有没有人知道正确的数学?
只是对下面代码的一个小解释.我通过获取它所在的行星的x和y坐标来计算我的机器人的位置,并执行一个圆形运动,其半径为行星的半径+ 55(这是我的精灵的舒适高度).
case 1:
positionX = AttachedPlanet.positionX + sin(timer/1.5)*(AttachedPlanet.planetRadius + 55);
positionY = AttachedPlanet.positionY + cos(timer/1.5)*(AttachedPlanet.planetRadius + 55);
timer = timer + 0.02;
break;
case 2:
positionX = AttachedPlanet.positionX + cos(timer/1.5)*(AttachedPlanet.planetRadius + 55);
positionY = AttachedPlanet.positionY + sin(timer/1.5)*(AttachedPlanet.planetRadius + 55);
timer = timer + 0.02;
Run Code Online (Sandbox Code Playgroud) 我正在尝试传递一个参数EIP作为注册的跳转指令EBX。
像这样,但没有CALL指示.我想我应该使用JMP,可能还有其他说明.
PUSH 5
PUSH 4
CALL Function
Run Code Online (Sandbox Code Playgroud) 如果你编译、链接和运行这样的东西:
global _start
section .text
_start:
jmp message
proc:
...
message:
call proc
msg db " y0u sp34k 1337 ? "
section .data
Run Code Online (Sandbox Code Playgroud)
我想检查地图上是否存在钥匙(本身就是一对)。
我是新来使用map的人,无法找到要检查键(一对)的函数。
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
typedef pair<ll,ll> my_key_type;
typedef map<my_key_type,ll> my_map_type;
int main()
{
my_map_type ma;
my_map_type::iterator it;
ma.insert(make_pair(my_key_type(30,40),6));
it=ma.find(30,40);
if(it==ma.end())
{
cout<<"not present";
return 0;
}
cout<<"present";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误-
no matching function for call to ‘std::map<std::pair<long long int, long long int>, long long int>::find(int, int)’ it=ma.find(30,40);
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <unistd.h>
int main(){
while(1){
int temp = rand();
int mod = temp % 7;
for(int i=0; i<mod; i++){
std::cout<<temp<<" ";
}
std::cout<<"\n";
//usleep(90000);
sleep(1);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我很好奇,如果您取消注释usleep(9000),为什么还会打印额外的换行符vs sleep(1)。

C中的函数是
void f(int* out, int* in, int nbElements){
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
由于int nbElements是第一个被压入堆栈in并且out具有可变大小,我如何访问 的值nbElements?据我了解,堆栈看起来像这样:
esp
ebp
return address # -4(%ebp)
1st element of int* out # -8(%ebp)
1st element of int* in # (%ebp - 8 - 4*nbElements)
nbElements # not sure how I can access the value of this
Run Code Online (Sandbox Code Playgroud)
那么如何在nbElements不知道其地址的情况下访问的值呢?
int x = 10,y = 18; char z = '*';
cin>> x >> y >> z;
cout<< x << " " << y << " " << z << endl
Run Code Online (Sandbox Code Playgroud)
给定输入“46”、“A”和“49”的顺序,我运行程序时的输出是“460*”(不包括引号。为什么会这样?
c++ ×5
assembly ×4
x86 ×4
att ×1
c++11 ×1
c++17 ×1
casting ×1
compilation ×1
function ×1
make-shared ×1
math ×1
objective-c ×1
variables ×1
vector ×1