代码块问题
Code blocks issues
嗨,我正在做一门课程,我很难处理我收到的错误消息,它们是:
error 'strtoul' was not declared in this scope
error 'print' was not declared in this scope
error 'printf' was not declared in this scope
我输入的代码是:
using namespace std;
int main (int argc, const char * argv[]) {
unsigned long int a, tmp;
a = strtoul("01011111000110001001001011010011",ULL,2);
print(a);
//We always work on "a" pattern
print(tmp = a >> 4);
print(tmp = a << 6);
print(tmp = a & (long int) 0x3);
print(tmp = a & (char) 0x3);
print(tmp = a | (unsigned short) 0xf00f);
print(tmp = a ^ (long int) 0xf0f0f0f0);
return 0;
}
//Function prints unsigned long integer in hexadecimal and binary notation
void print(unsigned long b)
{
int i, no_bits = 8 * sizeof(unsigned long);
char binary[no_bits];
//Print hexadecimal notation
printf("Hex: %Xn", b);
//Set up all 32 bits with 0
for (i = 0; i < no_bits; i++) binary[i] = 0;
//Count and save binary value
for (i = 0; b != 0; i++) {
binary[i] = b % 2;
b = b/2;
}
//Print binary notation
printf("Bin: ");
for (i = 0 ; i < no_bits; i++) {
if ((i % 4 == 0) && (i > 0)) printf(" ");
printf("%d", binary[(no_bits - 1) - i]);
}
printf("nn");
}
但我一直得到错误的台面:
error 'strtoul' was not declared in this scope
error 'print' was not declared in this scope
error 'printf' was not declared in this scope
无论我尝试什么,当我尝试声明它们时,我都会收到相同的错误消息,有什么帮助吗??
非常感谢
Ben
您需要在程序的顶部包含以下头文件:
#include <stdlib.h>
#include <stdio.h>
stdio库允许您执行输入/输出操作,stdlib库定义了几个通用函数,包括将字符串转换为无符号长整数。
您将希望将print
方法移动到main
之前,并且在调用strtoul
时也应该将ULL
更改为NULL
,因为我认为这是一个拼写错误。你可以在我提供的链接中查看文档。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在java中解决这段代码时面临循环中的问题
- 将鼠标悬停在问题上时与预期">"相关的代码错误
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 读取最后一行代码算法 - c++ 时出现问题
- 这个带有模板<类 Vector 的C++代码片段有什么问题>
- Xcode 语义问题引用或以前定义的代码
- 需要以下代码的帮助,下面的代码有什么问题
- 我无法在Visual Studio代码中使用CIN输入答案,它说输入您的年龄,但它说只读文本编辑器如何解决这个问题?
- 如何在代码问题中解决此问题 代码强制
- C 代码问题?编译器问题?代码块
- C - 如果语句问题.代码将不会运行其他,否则
- 简单的NOOB C 输入/输出问题:代码错误
- NDK:0xdeadd00d时虚拟机中止和致命信号 11 (SIGSEGV) 的问题(代码 = 1)
- 编译问题 - 代码 C2129
- c++问题代码段
- 模板作用域问题代码无法编译
- 基本 CUDA 程序的问题.代码或编译器