#include<stdio.h>
#include<conio.h>
unsigned * bin(unsigned n) {
unsigned a[16];
int i = 0, j = 0;
for (i = 0; i < 16; i++) {
a[i] = n & 0x1;
n = n >> 1;
}
return a;
}
void main() {
unsigned n = 5;
int i = 0;
unsigned * a = bin(n);
for (i = 15; i >= 0; i--) {
printf("%d\n", (*(a + i)));
}
getch();
}
Run Code Online (Sandbox Code Playgroud)
请帮助这个二进制转换不起作用.我正在尝试x^n使用二进制转换进行计算.可以任意帮助??
这个脚本中的第五行有什么问题(我已经包含了给我错误的代码片段,实际的错误列在代码后面的底部和完成脚本的链接)?
#! /bin/bash
INSTALLDIR=/usr/local/mapguideopensource
CLEAN_FLAG=0
while [ $# -gt 0 ]; do # Until you run out of parameters...
case "$1" in
-prefix|--prefix)
INSTALLDIR="$2"
shift
;;
-clean|--clean)
CLEAN_FLAG=1
shift
;;
-help|--help)
echo "Usage: $0 (options)"
echo "Options:"
echo " --prefix [installation directory]"
echo " --clean [clean all objects and binaries in Oem]"
echo " --help [Display usage]"
exit
;;
esac
shift # Check next set of parameters.
done
Run Code Online (Sandbox Code Playgroud)
这是我在 Linux (REHL5) 上运行这个 bash 脚本时遇到的错误:
: command not founde 4:
: …Run Code Online (Sandbox Code Playgroud) class parent {
virtual ~parent();
private:
int father_private;
int common;
}
~parent() {
common = 1;
}
class child: public parent {
~child();
private:
int common;
}
~child() {
common = 2;
}
Run Code Online (Sandbox Code Playgroud)
根据上述逻辑,预计会执行以下步骤:
在第2步中,"这是常见的=孩子的共同点"吗?
我发现地址不一样所以它可能意味着编译器不会取名,而是在类中使用offeset.因此,步骤2的分配可能会将1写入未知地址并导致意外崩溃,我是对的吗?
我发现Andorid本机流有一些类,其构造函数或析构函数可以访问其私有数据成员.它使得继承性成为上述问题的极其困难.你是如何解决这个问题的?
你好,所以我基本上都是想做这样的事情.
PrintOpt("Hello | I | Am | Awesome");
Run Code Online (Sandbox Code Playgroud)
在我的PrintOpt代码中
void PrintOpt(char* Text){
if(!strcmp(Text, " | ")){
Text = "\n";
}
printf(Text);
}
Run Code Online (Sandbox Code Playgroud)
我希望它能像这样打印出来
Hello
I
Am
Awesome
(On a new line)
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,它不打印任何东西.有谁知道为什么这不起作用?谢谢
我正在使用带有SDL2的OpenGL 4.4.我试图渲染一个带有顶点(-1,-1,0),(1,-1,0),(0,1,0)的简单三角形.但是,当我认为我正确地做了一切时,没有任何东西被画出来.
我从项目中提取并重新组织了相关代码:
#include <cerrno>
#include <cstring>
#include <exception>
#include <fstream>
#include <iostream>
#include <string>
#include <GL/glew.h>
#include <GL/glu.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
void init();
void cleanUp();
std::string loadShader(std::string filepath);
void checkShaderSuccess(GLuint shader);
SDL_Window* win;
SDL_GLContext glContext;
GLuint program, vertShader, fragShader, vao, vbo;
class GenError: public std::exception {
public:
GenError():
exception(), msg("") {}
GenError(const std::string& m):
exception(), msg(m) {}
virtual ~GenError() throw() {}
virtual const char* what() const throw() {
return msg.c_str();
}
private:
std::string msg;
};
int main() { …Run Code Online (Sandbox Code Playgroud) 所以我一直在尝试获取数组大小及其元素的输入,然后将元素显示到屏幕上,但是当我举例来说数组的大小:7数组的元素:1 2 3 4 5 6 7输出是:
1
2
3
4
5
6
6
Run Code Online (Sandbox Code Playgroud)
代码 :
#include <iostream>
using namespace std;
int main () {
int n , Arr[n];
cout << "please put the size of the array " ;
cin >> n;
cout << "please enter array's elemets ";
for (int k=0; k<n ; k++) {
cin >> Arr[k];
}
for (int i=0;i<n;i++){
cout << Arr[i] << endl;
}
}
Run Code Online (Sandbox Code Playgroud) char sentence[] ={'k','k','k','k','k','k','k','k'}; // (8 character)
std::cout << sentence << std::endl;
Run Code Online (Sandbox Code Playgroud)
那么输出就是kkkkkkkk.
但是如果我们递减数组的字符(即前面的数组在少于 8 个字符之后有 8 个字符)
char sentence[] ={'k','k','k','k','k','k','k'}; // ( 7 character)
std::cout << sentence << std::endl;
Run Code Online (Sandbox Code Playgroud)
输出:
kkkkkkk`\363\277\357\376.
Run Code Online (Sandbox Code Playgroud) 要读一些东西,我们需要有地方可以读;也就是说,我们需要在计算机内存中的某个地方来放置我们所读取的内容。我们将这样的“场所”称为对象。对象是一个内存区域,其类型指定可以在其中放置什么类型的信息。命名对象称为变量。例如,将字符串放入变量中,将整数放入变量中。您可以将对象视为一个“盒子”,您可以在其中放入该对象类型的值
stringint
对象是一个内存区域,其类型指定可以在其中放置什么类型的信息?在这里他们给出了一个整数和字符串的例子,就像内置的数据类型一样,我已经知道一些oop,所以我有点困惑,因为就像我认为一个对象是它自己的独立实体,有自己的用户创建的数据类型?我知道所有对象都有自己的内存区域,但它们基本上都是调用 int 类型的变量,age,值为 42 的对象。它是否正确?
我正在开发一个简单的操作系统,并且遇到了一些输出闪烁的问题(请参阅此剪辑)。除了内存问题之外,我很不知道是什么原因造成的。
内核.cpp
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
#define FPS 30
#define PIT_HERTZ 1193131.666
#define CLOCK_HIT (int)(PIT_HERTZ/FPS)
const unsigned char font[128-32][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0020 (space)
{ 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00}, // U+0021 (!)
{ 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0022 (")
{ 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00}, // U+0023 (#)
{ 0x0C, 0x3E, 0x03, 0x1E, …Run Code Online (Sandbox Code Playgroud) 在C++中,如果我打印一个尚未赋值的变量会怎样?以下两个代码给出了两个不同的结果.此外,第一个在每个编辑中给出不同的结果,第二个每次打印0.为什么?
int main() {
int x = 1;
int y; // No value has been assigned
if (x) {
cout << y; // without using endl
// prints different value each time
}
}
Run Code Online (Sandbox Code Playgroud)
与
int main() {
int x = 1;
int y; // y is not initialized
if (x) {
cout << y << endl; // using endl
// prints 0
}
}
Run Code Online (Sandbox Code Playgroud)