- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
考虑这个示例程序:
#include <cstdio>
#include <cwchar>
#include <string>
int main()
{
std::string narrowstr = "narrow";
std::wstring widestr = L"wide";
printf("1 %s \n", narrowstr.c_str());
printf("2 %ls \n", widestr.c_str());
wprintf(L"3 %s \n", narrowstr.c_str());
wprintf(L"4 %ls \n", widestr.c_str());
return 0;
}
这个的输出是:
1 narrow
2 wide
我想知道:
narrowstr
是 UTF8 而 widestr
是 UTF16 会有什么不同吗?最佳答案
你需要做的:
wprintf(L"3 %hs \n", narrowstr.c_str());
wprintf(L"4 %s \n", widestr.c_str());
为什么?因为对于 printf
,%s 表示窄字符字符串。对于 wprintf
,%ls 表示宽。
但是,对于 wprintf
,%s 意味着宽,%ls 本身意味着宽。 %hs 意味着狭窄(两者都适用)。对于 printf
、%s,这种方式仅表示 %hs
在 VC++/Windows 上,%S
(大写 S)会反转效果。因此 printf("%S")
表示宽,而 wprintf("%S")
表示窄。这对 _tprintf
很有用。
关于c++ - printf ("%s")、printf ("%ls")、wprintf ("%s") 和 wprintf ("%ls") 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26816547/
如果我执行 ls -la,我会得到如下结果 total 16 drwxr-xr-x 4 rockse staff 136 Apr 28 16:55 . drwx------+ 23 rocks
我找到了一些Linux文件,当我键入ls -lah时,它将输出以下权限格式: ... drwxr-xr-x. 2 root root ... -rw-rw-r--. 1 root r
我正在尝试从 python 执行 ls -l 来检查文件的最后修改日期。 os.listdir 不显示长列表格式。subprocess.call 显示格式,但实际上打印它,并返回 0。我希望能够将其放
以下 shell 函数定义卡在 Cygwin 的 bash 控制台 (RHEL/Ubuntu) 中,当它被调用时它只是退出终端。 $ function ls { ls; } $ ls 为什么会出现这种
为什么这两个命令的输出不同: ls | cat ls 第一个似乎用换行符分隔文件名。 这也适用于命令 suc 有 ls > outfile 和类似的东西。 我使用的是 Mac OSX,如果这有什么不同
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我使用 eshell-parse-command 'ls -l' 得到了这个: (progn (eshell-trap-errors (eshell-named-command "l
如何使用 RegExp 在 JavaScript 中实现类似于 alias 的功能? ALIAS = [{pattern: /^ls[$ ]/, replace: 'ls --color '}] s
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在编写一个 shell 程序,当将值传递给 execv() 时,我需要一个指向程序名称的 char 指针(即 ls),我需要一个指向参数的 char 指针数组的指针。 我会检查并解析用户的输入,如
我对使用 bash 编写脚本还比较陌生,并编写了以下脚本: # Set variables logfile=/tmp/peter/logfile.log indir=/mls/indir/IG/ te
所以基本上我有一个任务要使用 strace 进行分析,ls 命令需要哪些系统调用才能提供与 ls -l 相同的信息。 但是对于 ls -l 命令有许多奇怪的系统调用,例如 stat 64 被调用时使用
我在 ubuntu 的文件夹中有一个文件夹列表。IE。/mnt/source/customcode/files/brands/下 root@a919794ec280:/mnt/source/custo
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
#include #include #include #include #include int flag; void catch (int sig) { if (sig == SIGI
我使用 Process 来调用 shell(zsh),我想 cd ~ 或其他一些目录,例如在 shell 中定义的 cd $PROJ_ROOT。但似乎无法处理这些 token 。如何解决这个问题? s
我在我的 Centos5 机器上运行了这个: ls -al & ; ls -al 我期待它在后台运行 ls -al,同时在前台运行 ls -al,并演示终端的输出是如何被破坏的通过这样做。 但是,我得
当我在 PowerShell 中使用 Get-ChildItem 时,我会得到目录中以行格式设置的项目列表。该列表经常会超出屏幕,如果我想查看列表的其余部分或以前的命令和输出,则迫使我向上滚动。我想为
我试图用所有必要的参数绕过调用 JNIEnv->DefineClass 方法,但当我尝试从 java 调用该方法时,它总是返回 java.lang.NoClassDefFoundError: ls.H
我是一名优秀的程序员,十分优秀!