z***m 发帖数: 1602 | 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" |
t**r 发帖数: 3428 | 2 很簡單吧,题目搞懂了没什么难点。
楼主哪里有问题? |
z***m 发帖数: 1602 | 3 如果有\n,输出的是string; 如果没有, readline输出什么呢? |
d**********6 发帖数: 4434 | 4 题目不是已经说好了吗,如果没有,缓存已读内容,call recv again and again直到遇
到n,每次call都append已读内容进缓存
【在 z***m 的大作中提到】 : 如果有\n,输出的是string; 如果没有, readline输出什么呢?
|
z***m 发帖数: 1602 | 5 我是问如何判断有没有读到n,
是不是如果read()返回的空字符串,就是没有遇到n,
到遇
【在 d**********6 的大作中提到】 : 题目不是已经说好了吗,如果没有,缓存已读内容,call recv again and again直到遇 : 到n,每次call都append已读内容进缓存
|
z***m 发帖数: 1602 | 6 不会这么简单吧?
string buffer;
while(true)
{
string line = recv();
buffer += readLine();
if (line.find("\n) == npos){
return buffer;
}
} |