In front: C primer is not suitable for "beginners", beginners still watch "C Primer Plus" I have not seen it, but the road to say that the hard work is good, learning C is really difficult! In fact, I have been looking back, I'm going back, I will repeat, because my heart is inert, it is not bad, in fact, if you think it is a matter of course, you may not know very clearly. So I am determined to see it again from my head. I want to implement the procedures and exercises from the head to the end, and write the experience and notes, the reason why this is for myself, one is for learning C primer and very painful people, I have heard a Ph.D. telling the C course, I feel that it is a waste of time, because according to my experience, the last part of each chapter of the textbook is the most useful. Part of the school is slightly over school because the exam will not test. Because it is self-study, there is often no one to answer when you encounter problems. The C Primer learning note on the Internet is too simple. There is not much value, before the fifth chapter, I have never encountered too much questions, I Skating the second chapter, after learning the chapter of the following, is qualified to see the second chapter. In order to better analyze C primer, I will look at the following books in my hand: "The C Programming Language" by bjarne stroustrup "The C Standard Library" by nicolai m.josuttis " Effective C "by Mayer" More Effective C "BY Mayer" C STL Chinese version "BY PJPLAGER" Master the standard C class "by Cameron Hughes, Tracey Hughes" STL for C programming "by David etc" Think In C "by bra" C University Tutorial "BY HM, PD ... ...... Chapter 5: Compilation of the ILIST class, change. C is .cpp; first, should put # Include "iostream.h" all modulate "#include" iostream ", the same fstream.h -> fstream; stddef.h -> cstddef, you may have to attach the corresponding file header for other programs, this is to see what the program is used Features; Second, increase the use of Namespace STD to the pre-processor; third, remove allocator fourth, g -o ilist.exe ilist.cpp ilistmain.cpp; success! 5.11 p202, about _current _current is pointing one IList_item pointer, meaning is always pointing to the IList_item item of current activity, if deleting an ilist's head, _current still pointing to the chain header is not a wonderful, so it is impossible to modify Remove and REMOVE_FRONT.
Chapter 6 MAIN0.CPP Program Note // Increase #include
Return 0;} // I first narrodely what the retrieve_text function is doing and how to do it, this function reads each line in the input text file, record its contents, why do you think, you think about it? Look - it reads the entered text file, looks, seeing String, put it in the vector in the vector, in the vote of the vector is the first line of the text file, and push it. How is it doing? First, it builds an IFStream object. This object represents yourself on behalf of you, then getting GetLine, pay attention to getLine is a Getline provided for stream, one is Getline provided for String in
Vector
a.outplease enter file name: alice_emma line read: Alice Emma has long flowing red hair Her Daddy saysline read:. when the wind blows through her hair, it looks almost alive, line read:. like a fiery bird in flight A beautiful fiery Bird, HE Tells Her, Line Read: Magical Butne, SHING, "LINE Read: She Tells Him, At the Same Time Wanting Him To Tell Her More.Line Read: Shyly, She Asks , "I mean, daddy, is there" Number of Lines: 6Maximum Length: 66longest Line: Like a Fiery Bird in flight. A Beautiful Fiery Bird, He Tells her, main1.cpp program Note #include
Please enter file name: "; cin >> file_name; ifstream infile (file_name.c_str (), ios :: in); if (! infile) {cerr <<" OOPS! Unable to open file "<< file_name <<" - bailing out! / n "; exit (-1);} else cout <<" / n "; vector
Text_file-> size (); line_pos ) {short word_pos = 0; string textLine = (* text_file) [line_pos]; cout << "textline: << textLine << endl; string :: size_type eol = textline.Length ); // This is the length of a line, even the spaces and symbols don't let String :: size_type pos = 0, prev_pos = 0; // Good, let us start counting.
While ((POS = TextLine.Find_First_OF ('', POS)))! = String :: Npos) {// For example: Alice Emma Has Long Flowing Red Hair. Her Daddy Says // EOL: 52 POS: 5 line: 0 Word: 0 Substring: Alice means that number to 52, the first line ends, the number of spaces appears (remember that Mr. Lippman said to start from 0), is the 0th OK, the first word is marked, // Location is 0, the content is Alice, then put the alice in Words, Words is a string vector, think about why // should be put into the vector, because you want to give a separate The word code, such as No. 0, No. 1, No. 2 ....... COUT << "eol:" << eol << "<<" POS: "<< POS <<" "<<" Line: "<< line_pos <<" "<<" Word: "<< Word_POS <<" << "Substring: << TextLine.Substr (prev_pos, pos-prev_pos <<" / n "; Words- > Push_back (TextLine.Substr (prev_pos, pos - prev_pos)); // Locations is a pair vector, which will become {(0, 0) ...} Locations-> push_back ( Make_pair (line_pos, word_pos); Word_POS ; POS ; prev_pos = POS;} Cout << "Last Word on line substring:" << TextLine.Substr (Prev_pos, POS-PREV_POS) << "/ n"; Words-> Push_Back (TextLine.Substr (Prev_pos, POS - Prev_pos); Locations-> Push_Back (make_pair (line_pos, word_pos);} Return New Text_loc (Words, Locations); // (Alice, (0, 0)) ........} // text_loc is a (Vector <
String> *, vector