【发布时间】:2021-01-05 14:41:45
【问题描述】:
visual studio 也给出了这些警告。写入“array1”时缓冲区溢出:可写大小为“18”字节,但可能会写入“16”字节。写入“array2”时缓冲区溢出:可写大小为“18”字节,但可能会写入“16”字节。
#include <iostream>
#include <string>
using namespace std;
int main()
{
int charCountForA1, charCountForA2;
cout << "How many character do you want for Array 1 ? ";
cin >> charCountForA1;
cout << endl;
cout << "How many character do you want for Array 2 ? ";
cin >> charCountForA2;
//dynamic declaration of memory
double* array1 = new double(charCountForA1);
double* array2 = new double(charCountForA2);
cout << endl;
//to get user inputs to fill the array 1
for (int n = 0; n < charCountForA1; n++) {
double x;
cout << "Enter the element for index " << n << " of Array 1: ";
cin >> x;
array1[n] = x;
}
cout << endl;
//to get user inputs to fill the array 1
for (int n = 0; n < charCountForA2; n++) {
double x;
cout << "Enter the element for index " << n << " of Array 2: ";
cin >> x;
array2[n] = x;
}
【问题讨论】:
-
double* array1 = new double(charCountForA1);-- 这并不像你认为的那样。 -
double* array1 = new double(charCountForA1);-->std::vector<double> array1(charCountForA1);另一行代码也一样。 -
如果下面的答案解决了您的问题,您应该接受它(单击相应答案旁边的复选标记)。这有两件事。它让每个人都知道您的问题已得到您满意的解决,并为帮助您的人提供帮助。 See here 以获得完整的解释。
-
顺便说一句
0xC0000374在这里是 STATUS_HEAP_CORRUPTION:docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/…
标签: c++