小编Har*_*vey的帖子

如何让mit-scheme返回浮点数?

(/ 4 3)作为答案返回4/3.获得1.3的最简单方法是什么?

scheme

9
推荐指数
1
解决办法
3391
查看次数

为什么我必须在C#中关闭()一个文件?

我知道这可能看起来很愚蠢,但为什么以下代码只有在我关闭()文件时才有效?如果我不关闭文件,则不会写入整个流.

脚步:

  1. 在表单加载上运行此代码.
  2. 显示后,使用鼠标关闭表单.
  3. 程序终止.

文件对象超出范围时,是否不应自动刷新或关闭?我是C#的新手,但我习惯在C++析构函数中添加对Close()的调用.

// Notes: complete output is about 87KB. Without Close(), it's missing about 2KB at the end.

// Convert to png and then convert that into a base64 encoded string.
string b64img = ImageToBase64(img, ImageFormat.Png);
// Save the base64 image to a text file for more testing and external validation.
StreamWriter outfile = new StreamWriter("../../file.txt");
outfile.Write(b64img);
// If we don't close the file, windows will not write it all to disk. No idea why
// …
Run Code Online (Sandbox Code Playgroud)

.net c#

9
推荐指数
2
解决办法
8577
查看次数

如何在Linux中使用POSIX方法从文件中读取Unicode-16字符串?

我有一个包含UNICODE-16字符串的文件,我想将其读入Linux程序.字符串是从Windows的内部WCHAR格式原始编写的.(Windows总是使用UTF-16吗?例如日文版)

我相信我可以使用原始读取和使用wcstombs_l进行转换来读取它们.但是,我无法确定要使用的语言环境.在我最新的Ubuntu和Mac OS X机器上运行"locale -a"会产生零区域设置,其名称中包含utf-16.

有没有更好的办法?

更新:正确的答案和下面的其他人帮助我指出使用libiconv.这是我用来进行转换的功能.我目前在一个类中将它转换为一行代码.

// Function for converting wchar_t* to char*. (Really: UTF-16LE --> UTF-8)
// It will allocate the space needed for dest. The caller is
// responsible for freeing the memory.
static int iwcstombs_alloc(char **dest, const wchar_t *src)
{
  iconv_t cd;
  const char from[] = "UTF-16LE";
  const char to[] = "UTF-8";

  cd = iconv_open(to, from);
  if (cd == (iconv_t)-1)
  {
    printf("iconv_open(\"%s\", \"%s\") failed: %s\n",
           to, from, strerror(errno));
    return(-1);
  }

  // How much space do we …
Run Code Online (Sandbox Code Playgroud)

linux windows unicode posix wchar-t

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

在组装中使用LODSB需要什么?

使用LODSB将相对地址加载到我的代码中的字符串所需的最少步骤是什么?

我有以下使用PXE引导的测试程序。我通过两种方式引导它:通过pxelinux.0和直接引导。如果我直接启动它,我的程序将打印两个字符串。如果我通过pxelinux.0引导,它将仅输出第一个字符串。

为什么?

答: 代码很好,初始地址数学错误。见下文。

工作技巧(两者):

  • 将方向标记设置为递增, cld
  • 设置dscs
  • 将字符串的地址(从头开始)放入 si
  • 将起始偏移量添加到 si

非工作技术(仅适用于pxelinux):

  • 根据以下内容计算新的段地址 (((cs << 4) + offset) >> 4)
  • 设置ds为那个。(A000或07C0)

在此处输入文字以解决Markdown中的错误

// Note: If you try this code, don't forget to set 
//       the "#if 0" below appropriately!

    .text
    .globl  start, _start

start:  
_start: 
_start1:    

    .code16

    jmp real_start

    . = _start1 + 0x1fe
    .byte 0x55, 0xAA

    // Next sector
    . = _start1 + 0x200

    jmp real_start

test1_str:
    .asciz  "\r\nTest: 9020:fe00"
test2_str:
    .asciz …
Run Code Online (Sandbox Code Playgroud)

x86 assembly segments

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

是否有可用的C++样式和/或标准示例文件?

虽然有很多关于编码风格,美化和执行的问题,但我还没有找到任何用作样式快速参考的示例C++文件.该文件应该是一页或两页长,并举例说明给定的编码标准/样式.

例如,谷歌C++风格指南是一个很好的参考,但我认为一个一到两页的代码以他们的风格写在墙上将在日常使用中更有用.

这些中的任何一个已经存在吗?

c++ coding-style

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

QAbstractItemModel :: index(row,column,parent)是否应该检查无效输入?

子类化QAbstractItemModel,我根据需要实现了自己的index()方法。我目前正在检查输入是否有效,但是我想知道这是否正确。我想知道为不存在的数据创建索引是否有效?也许在插入行或列时?

码:

QModelIndex LicenseDataModel::index(int row, int column, const QModelIndex & /*parent*/) const
{
    /// TODO: Is this necessary? Should we avoid creating invalid indexes? Or could this
    /// be a bug?
    if (validRowColumn(row, column))
        return createIndex(row, column);
    return QModelIndex();
}
Run Code Online (Sandbox Code Playgroud)

qt

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

标签 统计

.net ×1

assembly ×1

c# ×1

c++ ×1

coding-style ×1

linux ×1

posix ×1

qt ×1

scheme ×1

segments ×1

unicode ×1

wchar-t ×1

windows ×1

x86 ×1