getline: identifier not found
Asked Answered
M

4

18

I have problem with getline().

I tried many examples and read other solutions, but that didn't solve my problem. I still have information 'getline: identifier not found'.

I included <stdio.h> <tchar.h> <iostream> <conio.h> <stdlib.h> <fstream> and still nothing.

#include "stdafx.h"

using namespace std;

int main(int argc, _TCHAR* argv[])
{
    string line;
    getline(cin, line);
    cout << "You entered: " << line << endl;
}

What do I need to do now?

I use Windows 7 64 bit and Visual Studio 2013.

Manasseh answered 3/1, 2015 at 13:7 Comment(3)
<string> would be the file in which you find std::getlineAculeus
en.cppreference.com/w/cpp/string/basic_string/getlineDacoity
Wildly guessing is not a good way to do programming. What prevented you from simply looking this up in the documentation?Marlee
M
40

Get used to simply reading the documentation for the language features that you use.
cppreference is quite clear that std::getline may found in string.

#include <string>
Marlee answered 3/1, 2015 at 17:15 Comment(0)
S
6

This should fix that:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main(int argc, _TCHAR* argv[]){
   string line;
   getline(cin, line);
   cout << "You entered: " << line << endl;
}
Sylvestersylvia answered 3/1, 2015 at 16:22 Comment(0)
H
5
#include <string>

Incidentally, "Murach's C++ Programming" textbook incorrectly states that getline() is in the iostream header (p. 71) which may lead to some confusion.

Howells answered 5/1, 2019 at 22:13 Comment(0)
S
4

You need to use

#include "string"

Read: std::getline

Shoveler answered 3/1, 2015 at 13:16 Comment(1)
Not "string" but <string> and I am having this problem as well having utilized cppreferenceBydgoszcz

© 2022 - 2024 — McMap. All rights reserved.