[英]How to print a long string using std::fprintf()?
I have a string of size 1024 and I would like to print it using std::fprintf(). 我有一个大小为1024的字符串,我想使用std :: fprintf()打印它。 I tried the following:
我尝试了以下方法:
FILE* m_file = .....;
char * msg = .....; // (size of 1024)
std::fprintf(m_file, "'%.1024s'\n", msg);
But in the output file, I see the msg printed only up to the length of 1000. 但是在输出文件中,我看到味精只能打印到1000的长度。
Could not find anything in documentation about it, does anyone have a clue? 在文档中找不到任何相关内容,有人知道吗?
Update: 更新:
It turns out that somewhere during our pipeline, the string is being cut at size 1000, and that's I did not see the whole string after fprintf 事实证明,在我们的管道中的某个地方,字符串被切成1000的大小,那是我在fprintf之后没有看到整个字符串
"I see the msg printed only up to the length of 1000." “我看到味精最多只能打印1000条。” -->
"%.1024s"
prints up to the the length of the string or 1024, whichever is smaller. ->
"%.1024s"
最多打印字符串的长度或1024,以较小者为准。
Apparently m_file[1000]
is '\\0'
. 显然
m_file[1000]
是'\\0'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.