输出总是 65535 个字符?

Output always 65535 characters?

本文关键字:字符 65535 输出      更新时间:2023-10-16

这是我的代码。

#include <iostream>
using namespace std;
int main() 
{
string s;
cin >> s;
cout << s.length();
return 0;
}

为什么即使我增加 s 中的字符,它也会给出 65535 的输出。 我在这里添加了 samle 输入 https://ideone.com/c2V8YX

Ideone FAQ 回答:

源代码、输入和输出的大小限制是多少?

64 kB.

请注意,此限制与C++语言无关,甚至与它的特定实现无关。限制是由Ideone造成的(这是可以理解的。您不希望允许人们上传无限的数据来填充您的服务器(。看来他们的行为是静默地截断输入。

这不是一个完全很棒的代码,但总体思路似乎是合理的。基本上读取块并附加它们(可能附加到 buffewr 而不是原始字符串(,但你明白了

#include <iostream>
using namespace std;
int main() {
string all;
char snippet[100];
while(cin.get(snippet, 100)){ all += snippet; }
cout<< all.length() << 'n';
return 0;
}