Compile Error

foo.cc: In function ‘int main()’:
foo.cc:6:25: error: no match for ‘operator=’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘int’)
    6 |         cin>>       sum=r;
      |                         ^
In file included from /nix/gcc-14-20241116/include/c++/14-20241116/sstream:40,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/complex:45,
                 from /nix/gcc-14-20241116/include/c++/14-20241116/ccomplex:39,
                 from stdc++.h:127:
/nix/gcc-14-20241116/include/c++/14-20241116/istream:715:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator=(std::basic_istream<_CharT, _Traits>&&) [with _CharT = char; _Traits = std::char_traits<char>]’
  715 |       operator=(basic_istream&& __rhs)
      |       ^~~~~~~~
/nix/gcc-14-20241116/include/c++/14-20241116/istream:715:33: note:   no known conversion for argument 1 from ‘int’ to ‘std::basic_istream<char>&&’
  715 |       operator=(basic_istream&& __rhs)
      |                 ~~~~~~~~~~~~~~~~^~~~~
foo.cc:5:13: warning: unused variable ‘n’ [-Wunused-variable]
    5 |         int n,y,r,sum=0;
      |             ^
foo.cc:5:15: warning: unused variable ‘y’ [-Wunused-variable]
    5 |         int n,y,r,sum=0;
      |               ^
foo.cc: At global scope:
foo.cc:8:9: error: expected unqualified-id before ‘if’
    8 |         if(y==2)
      |         ^~
foo.cc:19:9: error: expected unqualified-id before ‘if’
   19 |         if(y==3)
      |         ^~
foo.cc:30:9: error: expected unqualified-id before ‘if’
   30 |         if(y==4)
      |         ^~
foo.cc:41:9: error: expected unqualified-id before ‘if’
   41 |         if(y==5)
      |         ^~
foo.cc:52:9: error: expected unqualified-id before ‘if’
   52 |         if(y==6)
      |         ^~
foo.cc:63:9: error: expected unqualified-id before ‘if’
   63 |         if(y==7)
      |         ^~
foo.cc:74:9: error: expected unqualified-id before ‘if’
   74 |         if(y==8)
      |         ^~
foo.cc:85:9: error: expected unqualified-id before ‘if’
   85 |         if(y==9)
      |         ^~
foo.cc:96:9: error: expected unqualified-id before ‘if’
   96 |         if(y==10)
      |         ^~
foo.cc:107:9: error: expected unqualified-id before ‘if’
  107 |         if(y==11)
      |         ^~
foo.cc:118:9: error: expected unqualified-id before ‘if’
  118 |         if(y==12)
      |         ^~
foo.cc:129:9: error: ‘cout’ does not name a type
  129 |         cout<<sum;
      |         ^~~~
foo.cc:130:9: error: expected unqualified-id before ‘return’
  130 |         return 0;
      |         ^~~~~~
foo.cc:131:3: error: expected declaration before ‘}’ token
  131 |   }
      |   ^

信息

递交者
类型
递交
题目
P1030 A1-4 分支结构练习:今年过去了多少天
语言
C++
递交时间
2025-04-09 19:59:07
评测时间
2025-04-09 19:59:07
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes