Меню

Ошибка идентификатор getline не определен

Kislorod1234

0 / 0 / 0

Регистрация: 15.05.2016

Сообщений: 12

1

02.02.2017, 19:04. Показов 14916. Ответов 4

Метки нет (Все метки)


Ругается на getline , пишет идентификатор не найден

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <clocale>
 
int main()
{
    setlocale(LC_ALL, "rus");
    string  str1, str2, str;
    string  f_name1, f_name2;
    cout << "VV. name file 1 n" << endl;
    getline (cin, f_name1);
    cout << "VV. name file 2 n" << endl;;
    getline (cin, f_name2);
    ifstream f;
    f.open (f_name1, ios_base::in);
    ifstream g;
    g.open(f_name2, ios_base::in);
    int j = 0;
    while (!f.eof())
    {
        getline(f, str1, '');
        getline(g, str2, '');
        if (!Comp(str1, str2)) j=Put(str, str2,j);
    }
    f.close();
    g.close();
    //запись в файл
    system("pause");
    return 0;
}

Подскажите в чем проблема

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



zss

Модератор

Эксперт С++

12627 / 10125 / 6097

Регистрация: 18.12.2011

Сообщений: 27,158

02.02.2017, 19:28

2

Лучший ответ Сообщение было отмечено Kislorod1234 как решение

Решение

Нету

C++
1
#include <string>

а cstring Не надо

Да, и зачем Вам локализация, если русский текст не используете



1



0 / 0 / 0

Регистрация: 15.05.2016

Сообщений: 12

03.02.2017, 08:35

 [ТС]

3

Спасибо. Подскажите можно ли открыть файл для чтения и для записи в конец одновременно?

Добавлено через 31 минуту
Еще не могу понять почему ругается на cin.getline(f,str,»); , я хочу дописать строку str в конец файла f



0



Эксперт CЭксперт С++

5094 / 2279 / 332

Регистрация: 20.02.2013

Сообщений: 5,598

Записей в блоге: 19

03.02.2017, 09:19

4

 Комментарий модератора 
Kislorod1234, пожалуйста, прочитайте правила форума.
Особое внимание обратите на пункты 4.4 и 5.16.

.



0



Модератор

Эксперт С++

12627 / 10125 / 6097

Регистрация: 18.12.2011

Сообщений: 27,158

03.02.2017, 09:54

5

Цитата
Сообщение от Kislorod1234
Посмотреть сообщение

cin.getline(f,str,»);

std::getline и istream::getline — это разные функции.
Читайте синтаксис в справке.
Кстати, она вызывается клавишей F1 (текстовый курсор должен стоять на том, о чем хотите получить справку).



0



For your first error, I think that the problem is in this declaration:

 const float APRICE = 6.00,
       float CPRICE = 3.00;

In C++, to declare multiple constants in a line, you don’t repeat the name of the type. Instead, just write

 const float APRICE = 6.00,
             CPRICE = 3.00;

This should also fix your last error, which I believe is caused by the compiler getting confused that CPRICE is a constant because of the error in your declaration.

For the second error, to use getline, you need to

#include <string>

not just

#include <cstring>

Since the getline function is in <string> (the new C++ string header) and not <cstring> (the old-style C string header).

That said, I think you’ll still get errors from this, because movieName is declared as an int. Try defining it as a std::string instead. You might also want to declare your other variables as floats, since they’re storing real numbers. More generally, I would suggest defining your variables as you need them, rather than all up at the top.

Hope this helps!

For your first error, I think that the problem is in this declaration:

 const float APRICE = 6.00,
       float CPRICE = 3.00;

In C++, to declare multiple constants in a line, you don’t repeat the name of the type. Instead, just write

 const float APRICE = 6.00,
             CPRICE = 3.00;

This should also fix your last error, which I believe is caused by the compiler getting confused that CPRICE is a constant because of the error in your declaration.

For the second error, to use getline, you need to

#include <string>

not just

#include <cstring>

Since the getline function is in <string> (the new C++ string header) and not <cstring> (the old-style C string header).

That said, I think you’ll still get errors from this, because movieName is declared as an int. Try defining it as a std::string instead. You might also want to declare your other variables as floats, since they’re storing real numbers. More generally, I would suggest defining your variables as you need them, rather than all up at the top.

Hope this helps!

#include<iostream>   
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include<fstream>
#include<string>

using namespace std;

  int countLines( ifstream& in  )
    {
        int count = 0;
        char line[80];
        if ( in.good() )
        {
            //while ( !feof( in ) )
                while( getline( in,line ) ) count++;
            in.seekg(ios::beg);
        }
        return count;
    }

No matching function for call get line
What does it mean?
I have included all of the headers but why I still can not call get line?

asked Jul 16, 2013 at 6:58

Pramono Wang's user avatar

1

You need to use a std::string instead of a character array for calling string’s getline() function. Replace your char line[80] with a std::string line and it will work.

Check the documentation here http://www.cplusplus.com/reference/string/string/getline/

answered Jul 16, 2013 at 6:59

Salgar's user avatar

SalgarSalgar

7,5471 gold badge25 silver badges39 bronze badges

1

#include<iostream>   
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include<fstream>
#include<string>

using namespace std;

  int countLines( ifstream& in  )
    {
        int count = 0;
        char line[80];
        if ( in.good() )
        {
            //while ( !feof( in ) )
                while( getline( in,line ) ) count++;
            in.seekg(ios::beg);
        }
        return count;
    }

No matching function for call get line
What does it mean?
I have included all of the headers but why I still can not call get line?

asked Jul 16, 2013 at 6:58

Pramono Wang's user avatar

1

You need to use a std::string instead of a character array for calling string’s getline() function. Replace your char line[80] with a std::string line and it will work.

Check the documentation here http://www.cplusplus.com/reference/string/string/getline/

answered Jul 16, 2013 at 6:59

Salgar's user avatar

SalgarSalgar

7,5471 gold badge25 silver badges39 bronze badges

1

У меня проблема с getline(),
Я пробовал много примеров и читал другие решения, но это не решило мою проблему. У меня еще есть информация 'getline: identifier not found',
я включен
<stdio.h> <tchar.h> <iostream> <conio.h> <stdlib.h> <fstream> и до сих пор ничего.

#include "stdafx.h"
using namespace std;

int main(int argc, _TCHAR* argv[])

{

string line;
getline(cin, line);
cout << "You entered: " << line << endl;

}

Что мне нужно сделать сейчас? Я использую Win7 64bit, MSVS2013.

1

Решение

Привыкнуть просто чтение документации для языковых функций, которые вы используете.
Соотношение совершенно ясно, что std::getline может найти в string,

#include <string>

8

Другие решения

Это должно исправить это:

#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;
}

5

#include "stdafx.h"#include <iostream>
#include <string>
using namespace std;
int main(int argc, _TCHAR* argv[]){
string line;
/*To consume the whitespace or newline between the end of a token and the
beginning of the next line*/

// eat whitespace
getline(cin >> ws, line);
cout << "You entered: " << line << endl;
}

0

#include <string>

Кстати, в учебнике «Программирование С ++» Мурача ошибочно говорится, что getline () находится в заголовке iostream (стр. 71), что может привести к некоторой путанице.

0

Here’s the code:

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

using namespace std;

int i, j, l, r1, r2, r3, n1, n2, n3, n4, rII, rIII;

string msg;

int rotor1[26] = { 4,10,12,5,11,6,3,16,21,25,13,19,14,22,24,7,23,20,18,15,0,8,1,17,2,9 };
int rotor2[26] = { 0,9,3,10,18,8,17,20,23,1,11,7,22,19,12,2,16,6,25,13,15,24,5,21,14,4 };
int rotor3[26] = { 1,3,5,7,9,11,2,15,17,19,23,21,25,13,24,4,8,22,6,0,10,12,20,18,16,14 };
int reflec[26] = { 24,17,20,7,16,18,11,3,15,23,13,6,14,10,12,8,4,1,5,25,2,22,21,9,0,19 };
char base[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
void RotorInput() {
	cout << "Input initial positions (0 to 25):n";
	cout << "First rotor: ";
	cin >> r1;
	cout << "Second rotor: ";
	cin >> r2;
	cout << "Third rotor: ";
	cin >> r3;
}
void RotorInitialization() {
	rotate(rotor1, rotor1 + r1, rotor1 + 26);
	rotate(rotor2, rotor2 + r2, rotor2 + 26);
	rotate(rotor2, rotor2 + r2, rotor2 + 26);
}
void MessageInput() {
	cout << "Input your message/code:n";
	getline(cin, msg);
	getline(cin, msg);
}
void Encription() {
	l = msg.size();
	for (j = 0; j < l; j++) {

	}
	for (i = 0; i < l; i++) {

		if (msg.at(i) == ' ') {
			cout << " ";
		}
		else {
			int x = distance(base, find(base, base + 26, msg.at(i)));
			n1 = rotor1[x];
			n2 = rotor2[n1];
			n3 = rotor3[n2];
			n4 = reflec[n3];
			n3 = distance(rotor3, find(rotor3, rotor3 + 26, n4));
			n2 = distance(rotor2, find(rotor2, rotor2 + 26, n3));
			n1 = distance(rotor1, find(rotor1, rotor1 + 26, n2));
			cout << base[n1];

			rII = (i + r2 + 1) % 26;
			rIII = (i + r3 + 1) % 676;

			rotate(rotor1, rotor1 + 1, rotor1 + 26);

			if (rII == 0) {
				rotate(rotor2, rotor2 + 1, rotor2 + 26);
			}
			else {}

			if (rIII == 0) {
				rotate(rotor3, rotor3 + 1, rotor3 + 26);
			}
			else {}
		}
	}
}
int main()
{
	RotorInput();
	RotorInitialization();
	MessageInput();
	Encription();
	cout << endl;
	system("pause");
	return 0;
}

I’m using VS windows, my friend who coded this was using another program, and it worked, but not on mine… I’m going crazy!

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка зарядки робота пылесоса xiaomi
  • Ошибка звуковая модель слова