#include <iostream>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <cstring>
#include <string>
using namespace std;
struct news
{
char a[10];
int n;
float r;
};
int main()
{
news k;
cin >> k;
cout << k.a << endl;
cout << k.n << endl;
cout << k.r << endl;
return 0;
}
Это дает мне полный экран ошибок. Кто-нибудь знает, как решить эту проблему? Спасибо!Как читать структурную переменную оптом с клавиатуры, которая содержит c-строку, int и float?
test.cc: In function ‘int main()’: test.cc:20: error: no match for ‘operator>>’ in ‘std::cin >> k’ /usr/include/c++/4.2.1/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:135: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:142: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:178: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:182: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:185: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:189: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:192: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:196: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:200: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:205: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:209: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:214: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:218: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:222: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:226: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits] /usr/include/c++/4.2.1/istream:250: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits]
полный экран ошибок – user1050165
И ... Является ли ваш метод частью ООП? Я просто начинающий C++, не начал работать в ООП. – user1050165
@ user1050165 Технически это потому, что 'istream' является объектом, и мы используем его методы (например,' operator >> ') – 0x499602D2