前言
复写argv参数
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc,char *argv[]) {
int i,j;
for (i=1;i<argc;i++) {
for (j=strlen(argv[i])-1;j>=0;j--) {
argv[i][j] = 'x';
}
}
getchar();
return 0;
}
获取标准输入
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
"time"
)
func main() {
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
s := fs.String("s", "", "string")
i := fs.Int("i", 123, "int")
argv, _ := bufio.NewReader(os.Stdin).ReadString('\n')
fs.Parse(strings.Fields(argv))
fmt.Println(*s, *i)
time.Sleep(time.Minute)
}
总结