Rust エラー「error: character literal may only contain one codepoint」が発生した場合の対処法

Rustで、エラー「error: character literal may only contain one codepoint」が発生した場合の対処法を記述してます。Rustのバージョンは1.62.0を使用してます。
環境
- OS windows11 home
- rustc 1.62.0
エラー全文
以下のコードで発生
fn main() {
let mut str: String = "a".to_string();
str.push_str('bc');
println!("{}", str);
}
エラー全文
error: character literal may only contain one codepoint
--> sample.rs:5:18
|
5 | str.push_str('bc');
| ^^^^
|
help: if you meant to write a `str` literal, use double quotes
|
5 | str.push_str("bc");
| ~~~~
error: aborting due to previous error
原因
文字列には「”(ダブルクォーテーション)」を使用する必要があるため
対処法
「”(ダブルクォーテーション)」を使用する
fn main() {
let mut str: String = "a".to_string();
str.push_str("bc");
println!("{}", str); // abc
}
-
前の記事
Dart 数値同士を比較する 2022.10.11
-
次の記事
sqlite テーブルのスキーマを確認する 2022.10.11
コメントを書く