when program run reader->update,vs throws a microsoft c++ error

i want to load a ‘nii.gz’ 3d file , but when program pass reader->update() ,vs2017 will give me a microsoft c++ error
: Microsoft C++ 异常: itk::ImageFileReaderException,位于内存位置 0x00000000002CF0F8 处。
here is my code

using PixelType = float;
constexpr unsigned int Dimension = 3;
const char* im_path = "C:/Users/Administrator/Desktop/test.nii.gz";
using ImageType = itk::Image<PixelType, Dimension>;
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(im_path);
std::string s = reader->GetFileName();
std::cout << s << std::endl;
ImageType::Pointer image = reader->GetOutput();
reader->Update();

Welcome @Bugmaker, reader->Update() has to be before reader->GetOutput().

Check the examples: https://itk.org/ITKExamples/src/IO/ImageBase/ReadAnImage/Documentation.html

1 Like