1

当我使用cout很长的字符串时,它不会输出整个字符串,只输出结尾。

std::string test[] = {"alotof text--sdfsdfsdfsdfsdfsfsdferer----248 characters"};
std::cout << *test << std::endl;

输出:er----248个字符

这只是字符串的结尾,大部分开头都被切断了

4

3 回答 3

1

将输出写入文件并检查内容是否在文件中。我猜你的字符串包含回车('\r')字符,这会导致输出的位置移动到行的前面,从而在视觉上覆盖已经写在这一行上的字符。但是,所有字符都应该在文件中可见。

于 2013-11-02T22:48:35.023 回答
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

似乎没有什么问题

于 2013-11-02T22:53:42.853 回答
0

我使用 Visual Studio 2010 C++ 编译器进行了测试,代码与您编写的完全一样,我的输出是:

335
alotof text--sdfsdfsdfsddfasdfsdfasdfadfadfadfadfdfadfadfadfadfadfadfadsfasdfasdfasdfasdfa
sdfafdasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfadsfasdf
asdfasdfasdfasdfasdfasdfasdfasdfasdfadsfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas
dfasdfasdfasdfasdfasdfasdfadsafsdffsdfsfsdferer----248 characters

对我来说很好。

于 2013-11-02T22:57:21.047 回答