初級 › error: no match for 'operator>>' の原因と直し方 › パターン5
error: no match for 'operator>>' の原因と直し方
std::cout に >> を使ったり、std::cin に << を使ったりと、ストリーム演算子の向きを取り違えたときに出るエラーです。
1 #include <iostream> 2 #include <string> 3 int main() { 4 std::string name; 5 std::cin __ name; ^ 6 std::cout << name << std::endl; 7 return 0; 8 }
main.cpp:5:14: error: no match for 'operator<<' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'std::string' {aka 'std::__cxx11::basic_string<char>'})
空欄を埋めてコンパイル・実行を通す
std::cinは入力用のストリームで、値を受け取る向きの>>しか受け付けません。
次の問題