1
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?

paiza.ioでrust その6

Posted at

概要

paiza.ioでrustやってみた。
練習問題やってみた。

練習問題

hello.cをコンパイル、実行せよ。

サンプルコード


use std::fs;
use std::io::{Write, BufWriter};
use std::process::Command;

fn main() {
		let b = "
#include <stdio.h>

int main() {
  printf(\"Hello World\");
}
";
        let mut f = BufWriter::new(fs::File::create("hello.c").unwrap()); 
		f.write(b.as_bytes()).unwrap();
		f.flush();

        let output0 = Command::new("gcc").arg("hello.c").output().expect("failed to execute process");
        let hello0 = output0.stderr;
        println!("{}", std::str::from_utf8(&hello0).unwrap());
        
        let output = Command::new("./a.out").output().expect("failed to execute process");
        let hello = output.stdout;
        println!("{}", std::str::from_utf8(&hello).unwrap());
}


実行結果


Hello World

成果物

以上

1
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
1
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?