提交 94ea1599 编写于 作者: F feilong

init helloworld

上级 1d87fc48
{
"node_id": "rust-7c394f164d8f44519521f03db08a1321",
"keywords": [],
"children": [],
"export": []
"children": [
{
"Rust的起源": {
"keywords": [
"Rust的起源",
"起源",
"Rust"
],
"children": []
}
}
],
"export": [
"helloworld.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "helloworld.md",
"notebook_enable": true
}
\ No newline at end of file
# Hello World
编写一个输出 "Hello,World!" 的 Rust 程序,以下错误的是?
## 答案
```rust
fn main() {
let str1 = "Hello,";
let str2 = "World!";
println!("{}", str1+str2);
}
```
## 选项
### 直接打印
```rust
fn main() {
let str = "Hello,World!";
println!("{}", str);
}
```
### 使用格式划宏拼接
```rust
fn main() {
let str = "Hello";
let str = format!("{},World", str);
println!("{}", str);
}
```
### 使用 String::from
```rust
fn main() {
let str1 = String::from("Hello");
let str2 = String::from("World");
let str = format!("{},{}!", str1, str2);
println!("{}", str);
}
```
### 使用mut+push_str
```rust
fn main() {
let mut str1 = String::from("Hello,");
let str2 = String::from("World!");
str1.push_str(str2.as_str());
println!("{}", str1);
}
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册