- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我知道您不应该将打印与 printf,cout 和 wprintf,wcout 混合使用,但是很难找到一个好的答案,为什么以及是否可以绕过它。问题是我使用了一个用 printf 打印的外部库,而我自己使用了 wcout。如果我做一个简单的例子,它工作正常,但从我的完整应用程序来看,它根本不打印 printf 语句。如果这真的是一个限制,那么就会有许多库无法与广泛的打印应用程序一起工作。我们非常欢迎对此有任何见解。
更新:
我把它归结为:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <readline/readline.h>
#include <readline/history.h>
int main()
{
char *buf;
std::wcout << std::endl; /* ADDING THIS LINE MAKES PRINTF VANISH!!! */
rl_bind_key('\t',rl_abort);//disable auto-complete
while((buf = readline("my-command : "))!=NULL)
{
if (strcmp(buf,"quit")==0)
break;
std::wcout<<buf<< std::endl;
if (buf[0]!=0)
add_history(buf);
}
free(buf);
return 0;
}
所以我想这可能是冲水问题,但我还是觉得很奇怪,我必须检查一下。
更新 -> 解决方法:
首先,wprintf也出现了同样的问题。但我发现添加:
std::ios::sync_with_stdio(false);
实际上成功了......(注意是假的,而不是我期望的那样......),唯一困扰我的是,我不明白为什么以及如何弄清楚它:-(
最佳答案
我认为您在谈论 std::ios_base::sync_with_stdio
,但 IIRC 默认情况下它是打开的。
关于c++ 将 printf 与 wprintf 混合(或将 cout 与 wcout 混合),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2708482/
考虑这个示例程序: #include #include #include int main() { std::string narrowstr = "narrow"; std::
我正在使用 wprintf 打印不同大小的 C 字符串。 wprintf(L"%-*.*ls ", PRINTED_WORD_LENGTH, PRINTED_WORD_LENGTH, word->st
我正在尝试使用以下代码打印用于执行程序的参数: #include "stdafx.h" #include #include int main(int argc, wchar_t* argv[]) {
以下code : #include main() { int fd; fpos_t pos; printf("stdout, "); fflush(stdout
我刚刚发现 %ws 是常识(对某些人来说),用于格式化 unicode 字符串,%wZ 也是如此——但是 msdn 没有在我能找到它们的地方记录这些。有很多人在网上分别写了这些有用的 printf 格
从 main 内部,我尝试调用 ParseInput,它返回一个指向字符串的宽字符指针,我想将其 wprintf 到控制台。迄今为止,代码可以编译,但 wprintf 在调用时不执行任何操作。很简单,
AllocConsole(); consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); WriteConsoleW(consoleHandle, L"qweą
当我写一个单元测试时,我偶然发现了 glibc 的一些奇怪的行为,关于 "%p" 和 NULL 指针. 如果我有这样一行 printf("NULL pointer is %p\n", NULL);,然
按照 opengl-tutorial.org 上的教程进行操作,意识到我不能直接用 printf 打印着色器编译日志,因为我是在 Windows 桌面应用程序中这样做的。我尝试使用此方法将其转换为 L
代码: #include int main() { printf("printf\n"); wprintf(L"wprintf\n"); } https://onlinegdb.co
众所周知,要打印类型为固定宽度整数类型(如 uint32_t)之一的变量值,您需要包含 cinttypes(在C++) 或 inttypes.h(在 C 中)头文件,并使用格式说明符宏,如 PRIu3
我对 fgetws 和 wprintf 有疑问。 NULL 当之前打开的文件中有特殊字符时返回。 fgets 没有这个问题。 我尝试使用 setlocale,这里推荐:fgetws fails to
代码: #include #include #define USE_W int main() { #ifdef USE_W const wchar_t *ae_utf16 = L"\x00
我有一个包含英语和希伯来语字符的 wchar_t 数组,当我使用 wprintf() 打印它时,它只打印英文字符。当我使用 _wsetlocale(LC_ALL, L"Hebrew") 时,我得到的希
当我尝试打印版权符号 ©与 printf或 write ,它工作得很好: #include int main(void) { printf("©\n"); } #include int m
1 wprintf 将 'Ω' 显示为 3A9 (UTF16) 真的很奇怪,但是 wctomb 转换wchar 到 CEA9 (UTF8),我的语言环境默认是 en_US.utf8。正如手册页所说,它
我在代码中同时使用 printf 和 wprintf 函数时遇到问题。如果先打印常规字符串,则 wprintf 不起作用。如果我先使用 wprintf,则 printf 不起作用。 #include
在 C 程序中,我使用 wprintf 在 Windows 控制台中打印 Unicode (UTF-16) 文本。这工作正常,但是当程序的输出重定向到日志文件时,日志文件的 UTF-16 编码已损坏。
我注意到了 #include wprintf( L"Hello, %s\n", "world" ); 在 Linux 下与标准 glibc 一起工作,同样的事情与 newlib 的工作方式不同。似乎
我正在制作一个用于评估和分析传递函数的小应用程序。尽管这个主题对某些人来说可能看起来很无聊,但我希望它至少看起来特别酷、专业和很棒等等......所以: 第 1 步:给我系数! [一堆数字] 第 2
我是一名优秀的程序员,十分优秀!