C++ 代码块问题

C++ 代码块问题,c++,printf,codeblocks,C++,Printf,Codeblocks,嗨,我正在做一个课程作业,我很难收到一条错误消息,它们是: 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[]) { unsign

嗨,我正在做一个课程作业,我很难收到一条错误消息,它们是:

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: %X\n", 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("\n\n");
}
无论我尝试什么,当我尝试并声明它们时,我总是收到相同的错误消息,有什么帮助吗

非常感谢


Ben

您需要在程序顶部包含以下头文件:

#include <stdlib.h>
#include <stdio.h>
#包括
#包括
该库允许您执行输入/输出操作,并且该库定义了几个通用函数,包括将字符串转换为无符号长整数


您需要将
print
方法移到
main
之前,并且在调用
strtoul
时,还应该将
ULL
更改为
NULL
,因为我认为这是一个打字错误。您可以查看我提供的链接中的文档。

好的,您是否包含了所需的头文件?他还需要转发声明打印或将其放在main之前。我如何转发声明它?我已经添加了你给我的两个建议,丹,谢谢你,但我仍然没有任何乐趣。我仍然收到错误消息:错误“print”未在此范围内声明,错误“ULL”未在此范围内声明,说我的头被腌了是一种轻描淡写的说法,编程对我来说一点也不容易,因此我感谢您的支持help@Benjamin将您的打印方法置于main之前,并将ULL更改为NULL,这可能是最初的打字错误。如果对你有效,请告诉我。我会更新我的答案,但我现在正在我的手机上发帖。嗨,丹,没有,还是没有乐趣,但是谢谢你为我做的尝试
#include <stdlib.h>
#include <stdio.h>