https://atcoder.jp/contests/abc012/tasks/abc012_1
この問題を下のように解きましたがエラーが出ます
c++
1#include <iostream> 2#include <string> 3using namespace std; 4int main (){ 5 int A,B,t; 6 cin>>A>>B; 7 t=A; 8 A=B; 9 B=t; 10 A=to_string(A); 11 B=to_string(B); 12 cout<<A+" "+B<<endl; 13 }
compiler.cpp: In function 'int main()':
compiler.cpp:10:16: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string'} to 'int' in assignment
10 | A=to_string(A);
| ~~~~~~~~~^~~
| |
| std::string {aka std::__cxx11::basic_string}
compiler.cpp:11:16: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string'} to 'int' in assignment
11 | B=to_string(B);
| ~~~~~~~~~^~~
| |
| std::string {aka std::__cxx11::basic_string}
int型をstringに変換しようとして、しかしto_stringが機能してないようなのですがどうしたら良いでしょうか?
回答2件
あなたの回答
tips
プレビュー