For main.CPP file in lines 32 and 33 on visual studio community 2022 it's saying that getline is unidentified why is that and how do i fix it.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

For main.CPP file in lines 32 and 33 on visual studio community 2022 it's saying that getline is unidentified why is that and how do i fix it.

C
00%
// read the studentName and courseName
getline (infile, studentName);
getline (infile, course);
// create an object of Student class
grade = new Student (studentName, course);
// loop till the end of file
while (!infile.eof())
{
infile >> num; //read in a value from the file.
if (infile.fail())
{
cout << "A non-numeric value was found in the file...Exiting program. << endl;
return 1;
}
//If the number is negative...
Belse if (num < 0)
{
cout << "A negative value was found in the file...Exiting program.
X 1 ΔΟ ↑↓
rror List
Entire Solution
Code
abc E0020
> C3861
C3861
X 3 Errors A 1 Warning ✪ 0 Messages Build + IntelliSense
Description
identifier "getline" is undefined
'getline': identifier not found
'getline': identifier not found
11
" << endl;
Project
Class
Class
Class
Ln: 32 Ch: 30
Search Error List
File
Main.cpp
Main.cpp
Main.cpp
TABS
CRL
▼ 0
Line
32
32
33
8
Transcribed Image Text:C 00% // read the studentName and courseName getline (infile, studentName); getline (infile, course); // create an object of Student class grade = new Student (studentName, course); // loop till the end of file while (!infile.eof()) { infile >> num; //read in a value from the file. if (infile.fail()) { cout << "A non-numeric value was found in the file...Exiting program. << endl; return 1; } //If the number is negative... Belse if (num < 0) { cout << "A negative value was found in the file...Exiting program. X 1 ΔΟ ↑↓ rror List Entire Solution Code abc E0020 > C3861 C3861 X 3 Errors A 1 Warning ✪ 0 Messages Build + IntelliSense Description identifier "getline" is undefined 'getline': identifier not found 'getline': identifier not found 11 " << endl; Project Class Class Class Ln: 32 Ch: 30 Search Error List File Main.cpp Main.cpp Main.cpp TABS CRL ▼ 0 Line 32 32 33 8
Expert Solution
Step 1

following are some ways to fix this:

basically, this is the problem with the header file

The C++ getline() is an in-built function defined in the <string> header file that allows accepting and reading single and multiple line strings from the input stream. In C++, the cin object also allows input from the user, but not multi-word or multi-line input. That's where the getline() function comes in handy.

include header on top  #include <string>

 

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY