当我使用cout
很长的字符串时,它不会输出整个字符串,只输出结尾。
std::string test[] = {"alotof text--sdfsdfsdfsdfsdfsfsdferer----248 characters"};
std::cout << *test << std::endl;
输出:er----248个字符
这只是字符串的结尾,大部分开头都被切断了
当我使用cout
很长的字符串时,它不会输出整个字符串,只输出结尾。
std::string test[] = {"alotof text--sdfsdfsdfsdfsdfsfsdferer----248 characters"};
std::cout << *test << std::endl;
输出:er----248个字符
这只是字符串的结尾,大部分开头都被切断了
将输出写入文件并检查内容是否在文件中。我猜你的字符串包含回车('\r'
)字符,这会导致输出的位置移动到行的前面,从而在视觉上覆盖已经写在这一行上的字符。但是,所有字符都应该在文件中可见。
我用这个测试过:
#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
似乎没有什么问题
我使用 Visual Studio 2010 C++ 编译器进行了测试,代码与您编写的完全一样,我的输出是:
335
alotof text--sdfsdfsdfsddfasdfsdfasdfadfadfadfadfdfadfadfadfadfadfadfadsfasdfasdfasdfasdfa
sdfafdasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfadsfasdf
asdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas
dfasdfasdfasdfasdfasdfasdfadsafsdffsdfsfsdferer----248 characters
对我来说很好。