我正在編寫一個程序來獲取數字的二進制表示。 我寫了這段代碼。生成二進制到二進制時出錯
#include <iostream>
using namespace std;
int main() {
int n, count = 0;;
int* br = new int();
cin >> n;
while (n>0) {
if (n % 2)
br[count] = 1;
else
br[count] = 0;
n /= 2;
count++;
}
cout << count << endl;
for (int i = count - 1; i >= 0; i--) {
cout << br[i];
}
return 0;
}
當我運行上面的程序我得到這個錯誤
Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffe8995a2dc in ntdll!RtlpNtMakeTemporaryKey() from C:\Windows\SYSTEM32\ntdll.dll
Single stepping until exit from function ntdll!RtlpNtMakeTemporaryKey,
which has no line number information.
gdb: unknown target exception 0xc0000374 at 0x7ffe8995a31c
Program received signal ?, Unknown signal.
0x00007ffe8995a31c in ntdll!RtlpNtMakeTemporaryKey() from C:\Windows\SYSTEM32\ntdll.dll
Single stepping until exit from function ntdll!RtlpNtMakeTemporaryKey,
which has no line number information.
[Inferior 1 (process 6368) exited with code 0377]
可能是什麼可能的原因。 我是C++新手。
優秀的東西。 – molbdnilo
如何使用'std :: vector'或者'std :: bitset'? –
這將是一個非常好的主意。 –