cin causes an exception throw when using xtensor

0

I am trying to write a program using xtensor and it was working fine until I tried to use 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;

With function definition:

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;
};

It works fine if I comment out the cin >> w. But when I include it I get Exception thrown at 0x004FF284 in File_Name.exe: 0xC0000005: Access violation executing location 0x004FF284. in the xstorage.hpp file. It also works fine if I comment out cout << show; but leave in cin >> w.

I'm not sure why this is. w isn't used at all. I think the exception is thrown at the cout << show part whenever cin >> w in included.

c++
arrays
exception
cin
xtensor
asked on Stack Overflow Sep 26, 2019 by roshoka • edited Sep 26, 2019 by roshoka

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0