0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rust で HashMap にループで値を代入

Posted at

HashMap にループで値を代入する方法です。

hash01.rs
// --------------------------------------------------------------------
/*
	hash01.rs

						Jul/11/2020
*/
// --------------------------------------------------------------------
use std::collections::HashMap;

// --------------------------------------------------------------------
fn main(){

	eprintln! ("*** start ***");

	let mut unit_aa:HashMap <String,f64> = HashMap::new ();

	for count in 0..5 {
        	let key = "key_".to_owned() + &count.to_string();
        	unit_aa.insert(key, count as f64);
		}

	println!("{:?}",unit_aa);

	eprintln! ("*** end ***");
}

// --------------------------------------------------------------------
Makefile
hash01: hash01.rs
	rustc hash01.rs
clean:
	rm  -f hash01

コンパイル

make

実行結果

$ ./hash01 
*** start ***
{"key_4": 4.0, "key_0": 0.0, "key_2": 2.0, "key_1": 1.0, "key_3": 3.0}
*** end ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?