endlなのかstd::endlなのか
ぜんぜんわからん。AtCoder ABC 95のA問題をc++で書いた
#include <iostream> #include <string> using namespace std; int main(){ char s[3]; int cout=0; cin >> s; for(int i =0; i <3 ; i++){ if(s[i] =='o'){ cout += 1; } } int ans = 700 + cout*100 ; std::cout << ans << std::endl; return 0; }
これはうごいた。
using namespace stdの部分をコメントアウトしてcinの頭にstd::をつけても動作する。これもなんとなくわかる。が、
c#include <iostream> #include <string> using namespace std; int main(){ char s[3]; int cout=0; cin >> s; for(int i =0; i <3 ; i++){ if(s[i] =='o'){ cout += 1; } } int ans = 700 + cout*100 ; cout << ans << endl; return 0; }
がわかんないんですね~。
コンパイルエラーらしく
> Executing task: g++ -std=gnu++1y -g -O2 95_A.cpp -o 95_A.exe < 95_A.cpp: In function 'int main()': 95_A.cpp:14:17: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<' cout << ans << endl; ~~~~~~~~~~~~^~~~~~~
って表示される。( ,,`・ω・´)ンンン
using namespace std;って書いてればstd::cout -> cout みたいに省略可能なんじゃないの??で調べ方がよくわからず困っている。
わかる方、どうかご教示願います...。