- #1
proton
- 350
- 0
I'm taking c++ and I'm having difficulty differentiating the two. My lecturer and textbook don't explain these well.
My lecture notes says that for getline:
"if the delimiter is found it is extracted but not stored. Use get() if you don't want this character to be extracted"
What does it mean by "extracted" or "stored"?
one of the examples the instructor provided was:
int main()
{
cout << "What year was your house built?\n";
int year;
cin >> year;
cout << "What is its street address?\n";
char address[80];
cin.getline(address,80);
cout << "Year built:" << year << "\n";
cout << "Address: " << address << "\n";
cout << "Done!\n";
return 0;
}
the output is:
What year was your house built?
1966
What is the street address?
Year built: 1966
Address
Done!
Now the book says that street address was skipped because cin.getline reads the newline and replacing it with get() will fix it since get() discards the newline. What does this have to do with extracting and storing?
I had another off-related question: With regards to abstract classes, what does instantiate mean? I understand how abstract classes work, but I don't understand how they can't "instantiate" objects
My lecture notes says that for getline:
"if the delimiter is found it is extracted but not stored. Use get() if you don't want this character to be extracted"
What does it mean by "extracted" or "stored"?
one of the examples the instructor provided was:
int main()
{
cout << "What year was your house built?\n";
int year;
cin >> year;
cout << "What is its street address?\n";
char address[80];
cin.getline(address,80);
cout << "Year built:" << year << "\n";
cout << "Address: " << address << "\n";
cout << "Done!\n";
return 0;
}
the output is:
What year was your house built?
1966
What is the street address?
Year built: 1966
Address
Done!
Now the book says that street address was skipped because cin.getline reads the newline and replacing it with get() will fix it since get() discards the newline. What does this have to do with extracting and storing?
I had another off-related question: With regards to abstract classes, what does instantiate mean? I understand how abstract classes work, but I don't understand how they can't "instantiate" objects