How to declare initialize and print vector of strings in Rust

2 Answers

0 votes
fn main() {
    let vec = vec!["rust".to_string(), "java".to_string(), "c".to_string(), "c++".to_string()];

    for (_, s) in vec.iter().enumerate() {
        println!("{}", s);
    }

}

 
 
/*
run:
 
rust
java
c
c++
 
*/

 



answered Aug 26, 2024 by avibootz
0 votes
fn main() {
    let vec = vec!["rust", "java", "c", "c++"]; 

    for (_, s) in vec.iter().enumerate() {
        println!("{}", s);
    }

}

 
 
/*
run:
 
rust
java
c
c++
 
*/

 



answered Aug 26, 2024 by avibootz

Related questions

...