To recap,the three main objectives in the Mystery Method are:
To attract a woman
To establish comfort, trust, and connection
To structure the opportunity to be seduced
(1) | istream& getline (istream& is, string& str, char delim);
|
---|---|
(2) | istream& getline (istream& is, string& str);
|
// extract to string #include <iostream> #include <string> #include <fstream> int main () { std::string name; std::cout << "Please, enter your full name: "; std::getline (std::cin,name); std::cout << "Hello, " << name << "!\n"; std::cout <<"reading from TheMisteryMethod.txt:\n"; std::ifstream pua("TheMisteryMethod.txt"); if(pua.is_open()) { std::string afc; std::getline (pua,afc,',');//以逗号作为分隔结束符 std::cout<<"\nafter getline (pua,afc,',') afc is:\n"; std::cout<<afc<<'\n'; std::getline (pua,afc);//默认换行为分割结束符 std::cout<<"\nafter getline (pua,afc) afc is:\n"; std::cout<<afc<<'\n'; std::getline (pua,afc,'\0');//以C风格字符串结束标志作为分割结束符 std::cout<<"\nafter getline (pua,afc,'斜杠0') afc is:\n"; std::cout<<afc; } else std::cout<<"打开文本失败!\n"; return 0; } /**************************************************** 运行结果如下: Please, enter your full name: wangshihui Hello, wangshihui! reading from TheMisteryMethod.txt: after getline (pua,afc,',') afc is: To recap after getline (pua,afc) afc is: the three main objectives in the Mystery Method are: after getline (pua,afc,'斜杠0') afc is: To attract a woman To establish comfort, trust, and connection To structure the opportunity to be seduced Process returned 0 (0x0) execution time : 3.345 s Press any key to continue. *****************************************************/
istream& getline (char* s, streamsize n );
istream& getline (char* s, streamsize n, char delim );
'\n'
) for the first form, anddelim for the second: when found in the input sequence, it is extracted from the input sequence, but discarded and not written tos.(n-1)
characters have already been written tos. Note that if the character that follows those (n-1)
characters in the input sequence is precisely thedelimiting character, it is also extracted and the failbit flag is not set (the extracted sequence was exactlyn characters long).'\0'
) is automatically appended to the written sequence ifn is greater than zero, even if an empty string is extracted.*this
).
// istream::getline example #include <iostream> // std::cin, std::cout int main () { char name[256], title[256]; std::cout << "Please, enter your name: "; std::cin.getline (name,256); std::cout << "\nPlease, enter your favourite book: "; std::cin.getline (title,256); std::cout<<"\nafter std::cin.getline (title,256) :\n "; std::cout << name << "'s favourite book is " << title<<'\n'; std::cout << "\nPlease, enter your favourite book again: \n"; std::cin.getline (title,256,' '); std::cout<<"\nafter std::cin.getline (title,256,' ') :\n "; std::cout << name << "'s favourite book is " << title; return 0; } /****************************************************** 运行结果如下: Please, enter your name: wangshihui Please, enter your favourite book: the mistery method after std::cin.getline (title,256) : wangshihui's favourite book is the mistery method Please, enter your favourite book again: the mistery method after std::cin.getline (title,256,' ') : wangshihui's favourite book is the Process returned 0 (0x0) execution time : 19.729 s Press any key to continue. *******************************************************/