avatar
z*m
1
Given 2 functions String recv() and String ReadLine()
recv() generates some string (Example:"123n45n6789").
ReadLine() should read the string being returned by recv() and print all
characters until the first n.
After that it should read the recv() string again and print the next
characters until the 2nd n.
Example: recv(): "123n45n6789"
ReadLine(): "123" //first call of ReadLine
ReadLine(): "45" // second call of ReadLine
However, the next sequence now doesn't have a n. So, once the end of the
string is hit, the ReadLine() function must call recv() again, and append
all characters until it reads a n.
Continuing the above example: ReadLine():6789abcde //Third call of ReadLine
recv():"abc"// still no n...so you must call recv() again
recv():"den"
avatar
t*r
2
很簡單吧,题目搞懂了没什么难点。
楼主哪里有问题?
avatar
z*m
3
如果有\n,输出的是string; 如果没有, readline输出什么呢?
avatar
d*6
4
题目不是已经说好了吗,如果没有,缓存已读内容,call recv again and again直到遇
到n,每次call都append已读内容进缓存

【在 z***m 的大作中提到】
: 如果有\n,输出的是string; 如果没有, readline输出什么呢?
avatar
z*m
5
我是问如何判断有没有读到n,
是不是如果read()返回的空字符串,就是没有遇到n,

到遇

【在 d**********6 的大作中提到】
: 题目不是已经说好了吗,如果没有,缓存已读内容,call recv again and again直到遇
: 到n,每次call都append已读内容进缓存

avatar
z*m
6
不会这么简单吧?
string buffer;
while(true)
{
string line = recv();
buffer += readLine();
if (line.find("\n) == npos){
return buffer;
}
}
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。