小编Joa*_*sen的帖子

为什么我不能读取超过4094个字符的UTF-16文件?

一些信息:

  • 我只在Linux上试过这个
  • 我和GCC(7.2.0)和Clang(3.8.1)一起尝试过
  • 根据我的理解,它需要C++ 11或更高版本

运行时会发生什么

我得到预期的字符串"abcd"重复,直到它达到4094个字符的位置.之后所有输出都是这个标志"?" 直到文件结束.

我怎么看待这个?

我认为这不是预期的行为,它必定是某个地方的错误.

你可以测试的代码:

#include <iostream>
#include <fstream>
#include <locale>
#include <codecvt>

void createTestFile() {
  std::ofstream file ("utf16le.txt", std::ofstream::binary);
  if (file.is_open()) {
    uint16_t bom = 0xFEFF; // UTF-16 little endian BOM
    uint64_t abcd = 0x0064006300620061; // UTF-16 "abcd" string
    file.write((char*)&bom,2);
    for (size_t i=0; i<2000; i++) {
      file.write((char*)&abcd,8);
    }
    file.close();
  }
}

int main() {
  //createTestFile(); // uncomment to make the test file

  std::wifstream file;
  std::wstring line;

  file.open("utf16le.txt");
  file.imbue(std::locale(file.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>));
  if …
Run Code Online (Sandbox Code Playgroud)

c++ linux utf-16 wstring wifstream

13
推荐指数
1
解决办法
399
查看次数

如何更改这些模块的这些 require 语句以使用 import 语句?

我希望停止使用require()以下模块的语句,因为 Node 版本 11 现在支持 ES6,但我找不到任何有关如何编写以下内容(除了express作为import语句)的文档:

import express from "express";
const http = require('http');
import bodyParser from 'body-parser';
const morgan = require('morgan');
Run Code Online (Sandbox Code Playgroud)

bodyParser它与formorgan和相同吗http

例如morgan我只见过:

import logger from 'morgan';

因为http我只看到:

import * as http from 'http';

javascript import module require node.js

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

import ×1

javascript ×1

linux ×1

module ×1

node.js ×1

require ×1

utf-16 ×1

wifstream ×1

wstring ×1