当我将cout
用于非常长的字符串时,它不输出整个字符串,只输出结尾。
std::string test[] = {"alotof text--sdfsdfsdfsdfsdfsfsdferer----248 characters"};
std::cout << *test << std::endl;
输出:er ---- 248个字符
这只是字符串的结尾,大多数开头被切断了
答案 0 :(得分:1)
将输出写入文件并检查内容是否在文件中。我猜你的字符串包含回车符('\r'
)字符,这些字符会导致输出的位置移动到行的前面,从而在视觉上覆盖已写在此行上的字符。但是,所有字符都应该在文件中可见。
答案 1 :(得分:0)
我测试了这个:
#include <iostream>
int main(){
std::string test[] = {"alotof text--sdfsdfsdfsddfasdfsdfasdfadfadfadfadfdfadfadfadfadfadfadfadsfasdfasdfasdfasdfasdfafdasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsafsdffsdfsfsdferer----248 characters"};
std::cout << test[0].length() << std::endl;
std::cout << *test << std::endl;
}
这是我的输出:
336
alotof text-- sdfsdfsdfsddfasdfsdfasdfadfadfadfadfadfadfadfadfadfadfadfadsfasdfasdfasdfasdfasdfafdasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsafsdffsdfsfsdferer----248 characters
似乎没有任何问题
答案 2 :(得分:0)
我使用Visual Studio 2010 C ++编译器进行了测试,并且编码与您编写的完全一样,我的输出是:
335
alotof text--sdfsdfsdfsddfasdfsdfasdfadfadfadfadfdfadfadfadfadfadfadfadsfasdfasdfasdfasdfa
sdfafdasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfadsfasdf
asdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas
dfasdfasdfasdfasdfasdfasdfadsafsdffsdfsfsdferer----248 characters
对我来说很好。