我正在尝试使用 xtensor 编写一个程序,并且在我尝试使用 cin 之前它运行良好:
auto w=5;
cout << "Enter the 'n' for an nxn matrix: ";
//cin >> w;
cout << w;
if (!cin) { cout << "FAIL"; return 0; }
xarray<double> t;
t = nxn_array(4);
return 0;
带函数定义:
xarray<double> nxn_array(unsigned int n) //shows original array being used
{
auto show = empty<double>({ n,n });
int c = 1; //lattic site index
for (unsigned int i = 0; i < n; ++i)
{
for (unsigned int j = 0; j < n; ++j)
{
show(i, j) = c;
++c;
}
}
cout << show;
return show;
};
如果我注释掉cin >> w
. 但是当我包含它时,我会Exception thrown at 0x004FF284 in File_Name.exe: 0xC0000005: Access violation executing location 0x004FF284.
进入xstorage.hpp
文件。如果我注释掉cout << show;
但留在cin >> w
.
我不确定这是为什么。w
根本不使用。我认为只要包含在该cout << show
部分就会引发异常cin >> w
。