ifstream ifile("中文路径")

ifstream ifile("中文路径");

char buffer[81];

ifile.getline(buffer,81,'\n');

buffer一直为空。原因是使用了中文路径,改为英文路径则不存在问题了!

是不是我选择字符集选的ascii,要用unicode才能支持中文。

或者使用其它的方法,使fstream支持中文路径:http://www.cppblog.com/gohan/archive/2008/05/11/49488.html

或者使用CStdioFile.

if (argc < 2) { return false; } //dcm-series保存路径 std::string filePath1 = argv[1]; std::string filePath = filePath1.substr(0, filePath1.find_last_of("\\") + 1); std::cout << "file Path= " << filePath << std::endl; std::string savePath = filePath ;//+ "1.dcm";//R"(1.dcm)"; // if (_access(savePath.c_str(), 0) == -1) // _mkdir(savePath.c_str()); int width = 4352;//config->ReadInt("Image", "width", 0); int height = 4352;//config->ReadInt("Image", "height", 0); float x_spacing = 1;//config->ReadFloat("Image", "x_spacing", 0); float y_spacing = 1;//config->ReadFloat("Image", "y_spacing", 0); float z_spacing = 0.0; //读取raw文件 unsigned short usMin = 65535; unsigned short usMax = 0; std::cout << "argv[1]: " << argv[1] << std::endl; long nLength = height * width * sizeof(unsigned short); std::ifstream ifile; ifile.open(argv[1], std::ios::binary); if (!ifile.good()) { std::cout<<"not open"<<endl; return -1; } ifile.seekg(0, ifile.end);//seek函数会把标记移动到输入流的结尾 long long lTotalSize = ifile.tellg();// tell会告知整个输入流(从开头到标记)的字节数量 std::cout << "lTotalSize: " << lTotalSize << std::endl; int nFrameNum = lTotalSize / nLength; int nDcmHeaderSize = lTotalSize % nLength; std::cout << "nFrameNum: " << nFrameNum << std::endl; std::cout << "nDcmHeaderSize: " << nDcmHeaderSize << std::endl; unsigned short* pData0 = new unsigned short[lTotalSize]; ifile.seekg(0, ifile.beg);//再把标记移动到流的开始位置 ifile.read(reinterpret_cast<char*>(pData0), lTotalSize); //read函数读取(拷贝)流中的length各字节到buffer ifile.close();
最新发布
04-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值