{"action":"created","issue":{"url":"https://api.github.com/repos/ReadingLab/Discussion-for-Cpp/issues/50","labels_url":"https://api.github.com/repos/ReadingLab/Discussion-for-Cpp/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/ReadingLab/Discussion-for-Cpp/issues/50/comments","events_url":"https://api.github.com/repos/ReadingLab/Discussion-for-Cpp/issues/50/events","html_url":"https://github.com/ReadingLab/Discussion-for-Cpp/issues/50","id":113012192,"number":50,"title":"ex12_24中ignore函数的作用","user":{"login":"csbdong","id":12005953,"avatar_url":"https://avatars.githubusercontent.com/u/12005953?v=3","gravatar_id":"","url":"https://api.github.com/users/csbdong","html_url":"https://github.com/csbdong","followers_url":"https://api.github.com/users/csbdong/followers","following_url":"https://api.github.com/users/csbdong/following{/other_user}","gists_url":"https://api.github.com/users/csbdong/gists{/gist_id}","starred_url":"https://api.github.com/users/csbdong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csbdong/subscriptions","organizations_url":"https://api.github.com/users/csbdong/orgs","repos_url":"https://api.github.com/users/csbdong/repos","events_url":"https://api.github.com/users/csbdong/events{/privacy}","received_events_url":"https://api.github.com/users/csbdong/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-23T12:45:59Z","updated_at":"2015-10-29T06:19:43Z","closed_at":null,"body":"代码如下：\r\n```C++\r\n#include <iostream>\r\n\r\nint main()\r\n{\r\n    // need to tell the size.\r\n    std::cout << \"How long do you want the string? \";\r\n    int size{0};\r\n    std::cin >> size;\r\n    char *input = new char[size+1]();\r\n    std::cin.ignore(); //*********************************************//\r\n    std::cout << \"input the string: \";\r\n    std::cin.get(input, size+1);\r\n    std::cout << input;\r\n    delete [] input;\r\n    // Test: if longer than the array size, we will lost the characters which are out of range.\r\n}\r\n```\r\n输入测试数据 5[Enter]sssss 测试无误，但是删去cin.ignore()后，测试发现输入5之后就不再接受输入。\r\n\r\n\r\nignore（）默认的参数是1,EOF表示清空缓冲区中的一个字符。但是在输入5之后敲击回车原则上是无影响的，因为cin>>size,中的cin>>该操作符是根据后面变量的类型读取数据。输入结束条件  ：遇到Enter、Space、Tab键。**对结束符的处理 **：丢弃缓冲区中使得输入结束的结束符(Enter、Space、Tab) 。\r\n\r\n删去cin.ignore()的条件下：\r\n此处输入5后，缓冲区内无残留数据，因此我认为不加cin.ignore()也是可以的，但是实践表明不行，不知道是为什么？\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ReadingLab/Discussion-for-Cpp/issues/comments/152090279","html_url":"https://github.com/ReadingLab/Discussion-for-Cpp/issues/50#issuecomment-152090279","issue_url":"https://api.github.com/repos/ReadingLab/Discussion-for-Cpp/issues/50","id":152090279,"user":{"login":"pezy","id":1147451,"avatar_url":"https://avatars.githubusercontent.com/u/1147451?v=3","gravatar_id":"","url":"https://api.github.com/users/pezy","html_url":"https://github.com/pezy","followers_url":"https://api.github.com/users/pezy/followers","following_url":"https://api.github.com/users/pezy/following{/other_user}","gists_url":"https://api.github.com/users/pezy/gists{/gist_id}","starred_url":"https://api.github.com/users/pezy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pezy/subscriptions","organizations_url":"https://api.github.com/users/pezy/orgs","repos_url":"https://api.github.com/users/pezy/repos","events_url":"https://api.github.com/users/pezy/events{/privacy}","received_events_url":"https://api.github.com/users/pezy/received_events","type":"User","site_admin":false},"created_at":"2015-10-29T06:19:43Z","updated_at":"2015-10-29T06:19:43Z","body":"> 因为cin>>size,中的cin>>该操作符是根据后面变量的类型读取数据。输入结束条件 ：遇到Enter、Space、Tab键。*对结束符的处理 *：丢弃缓冲区中使得输入结束的结束符(Enter、Space、Tab) 。\r\n\r\n这个\"丢弃原则\" 是哪里规定的?"}}