istream's getline()
Would someone please explain (and give an example) of how to use istream''s getline(char *pch, int nCount,char delimeter=''\n'') function?
And Unless Microsoft has changed any oftheir happy little games, your stuck with it.Patrick Nortin ~TechTV''s "The ScreenSavers"~
istream::getline(char*s, streamsize n, char delim=''\n'') is used to get a line from a stream. It extracts characters from the stream and stores them into successive locations in the array pointed by s. Characters are extracted until either (n - 1) characters have been extracted, the delimiter (parameter delim or ''\n'' if not specified) is found, or if the end of file or any error occurs in the input sequence.
If the delimiter is found it is extracted but not stored (meaning it is read from the stream, put not stored in the array). An ending null character is automatically appended after the data stored in s.
For example:
If you want to extract a line from a stream into a string (and not an array as above), you have to use the std::getline(istream& istr, string& str).
Please note that if you use Visual C++, the C++ library contains a serious bug that results in getline reading one character too many. This holds for both the istream::getline member function and the std::getline template function. See my sig for a link to fixes for this bug (and others).
HTH
If the delimiter is found it is extracted but not stored (meaning it is read from the stream, put not stored in the array). An ending null character is automatically appended after the data stored in s.
For example:
#include <iostream>using namespace std;int main() { char name[256], title[256]; cout << "Enter your name: "; cin.getline(name, 256); cout << "Enter your favourite movie: "; cin.getline(title, 256); cout << name << "''s favourite movie is " << title;}
If you want to extract a line from a stream into a string (and not an array as above), you have to use the std::getline(istream& istr, string& str).
Please note that if you use Visual C++, the C++ library contains a serious bug that results in getline reading one character too many. This holds for both the istream::getline member function and the std::getline template function. See my sig for a link to fixes for this bug (and others).
HTH
Some useful C++ links:Free multiplatform ANSI C++ Standard Library implementationVisual C++ 6.0 STL fixesVisual C++ 6.0 noncompliance issuesC++ FAQ Lite
quote:
Original post by Kylotan
You don''t have a sig any more
http://www.dinkumware.com/vc_fixes.html
Ah, that''s pretty stupid of me

HTH
Some useful C++ links:
Free multiplatform ANSI C++ Standard Library implementation
Visual C++ STL fixes
Visual C++ 6.0 noncompliance issues
C++ FAQ Lite
Some useful C++ links:Free multiplatform ANSI C++ Standard Library implementationVisual C++ 6.0 STL fixesVisual C++ 6.0 noncompliance issuesC++ FAQ Lite
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement