Visual c++ 为什么会触发断点?
我已经在这段代码中广泛地寻找了这个问题,但我似乎无法弄清楚我犯了什么悲惨的错误以及为什么它会触发断点。 (在3或4次输入后,它会触发,我不知道为什么它在开始时没有触发,或者是什么原因导致它)Visual c++ 为什么会触发断点?,visual-c++,triggers,breakpoints,Visual C++,Triggers,Breakpoints,我已经在这段代码中广泛地寻找了这个问题,但我似乎无法弄清楚我犯了什么悲惨的错误以及为什么它会触发断点。 (在3或4次输入后,它会触发,我不知道为什么它在开始时没有触发,或者是什么原因导致它) #包含//函数getch() #包含//用于多个通用功能 #包含//用于文件处理 #包含//用于格式化输出 #包括//用于cin、cout和系统 #字符串数据类型的include// 使用命名空间std;//例如,“std::cout”可以缩写为“cout”。 字符串转换器Dectobin(int-dec)
#包含//函数getch()
#包含//用于多个通用功能
#包含//用于文件处理
#包含//用于格式化输出
#包括//用于cin、cout和系统
#字符串数据类型的include//
使用命名空间std;//例如,“std::cout”可以缩写为“cout”。
字符串转换器Dectobin(int-dec)
{
int*arrayHex,arraySize=0;
arrayHex=新整数[];
字符串s=“”;
int r=dec;
for(int i=0;r!=0;i++)
{
arrayHex[i]=r%2;
r=r/2;
arraySize++;
}
对于(int j=0;j输入;
如果(输入!=-1)
{
coutarrayHex=new int[]
是您的问题-C\C++不支持动态调整数组大小。您需要为要分配的数组指定一个大小,否则将导致内存块溢出
#include <conio.h> // For function getch()
#include <cstdlib> // For several general-purpose functions
#include <fstream> // For file handling
#include <iomanip> // For formatted output
#include <iostream> // For cin, cout, and system
#include <string> // For string data type
using namespace std; // So "std::cout" may be abbreviated to "cout", for example.
string convertDecToBin(int dec)
{
int *arrayHex, arraySize = 0;
arrayHex = new int[];
string s = " ";
int r = dec;
for (int i = 0; r != 0; i++)
{
arrayHex[i] = r % 2;
r = r / 2;
arraySize++;
}
for (int j = 0; j < arraySize; j++)
{
s = s + to_string(arrayHex[arraySize - 1 - j]);
}
delete[] arrayHex;
return s;
}
string convertDecToOct(int dec)
{
int *arrayHex, arraySize = 0;
arrayHex = new int[];
string s = " ";
int r = dec;
for (int i = 0; r != 0; i++)
{
arrayHex[i] = r % 8;
r = r / 8;
arraySize++;
}
for (int j = 0; j < arraySize; j++)
{
s = s + to_string(arrayHex[arraySize - 1 - j]);
}
delete[] arrayHex;
return s;
}
int main()
{
int input = 0;
while (input != -1)
{
cout << "\nEnter a decimal number (-1 to exit loop): ";
cin >> input;
if (input != -1)
{
cout << "Your decimal number in binary expansion: " << convertDecToBin(input);
cout << "\nYour decimal number in octal ecpression: " << convertDecToOct(input);
}
}
cout << "\n\nPress any key to exit. . .";
_getch();
return 0;
}