Erlang-fwrite瓷砖

Erlang-fwrite瓷砖,erlang,Erlang,如果字符串包含~,我似乎无法将其打印到标准输出 > A = "/.git". > io:fwrite(A). /.gitok > B = "~/.git". > io:fwrite(B). ** exception error: bad argument in function io:format/3 called as io:format(<0.50.0>,"~/.git",[]) >A=“/.git”。 >io:fwrite(A)。 /吉托

如果字符串包含
~
,我似乎无法将其打印到标准输出

> A = "/.git".
> io:fwrite(A).
/.gitok

> B = "~/.git".
> io:fwrite(B).
** exception error: bad argument
 in function  io:format/3
    called as io:format(<0.50.0>,"~/.git",[])
>A=“/.git”。
>io:fwrite(A)。
/吉托克先生
>B=“~/.git”。
>io:fwrite(B)。
**异常错误:参数错误
在功能io中:格式/3
称为io:format(,“~/.git”,[])

如何将带有平铺的字符串打印到标准输出?

您可以使用控制序列~p>将带有平铺的字符串打印到标准输出

 ~ → erl
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V8.3  (abort with ^G)
1>  B = "~/.git".
"~/.git"
2> io:fwrite("~p",[B]).
"~/.git"ok
3> io:fwrite("~p~n",[B]).
"~/.git"
ok
4>
如果字符串包含
~
,我似乎无法将其打印到标准输出

> A = "/.git".
> io:fwrite(A).
/.gitok

> B = "~/.git".
> io:fwrite(B).
** exception error: bad argument
 in function  io:format/3
    called as io:format(<0.50.0>,"~/.git",[])
要格式化输出,请构造一个字符串,其中包含以
~
开头的格式序列。Erlang认为您的字符串包含一个格式序列。如果希望Erlang输出一个文本
~
,可以使用另一个
~
对其进行转义:

22> io:format("~~/.git~n").
~/.git
ok

不需要格式化时,不要使用
io:fwrite/1,2,3
io:format/1,2,3
。这些函数适用于需要C语言中的
printf()
fprintf()
的地方。如果您只想输出已准备好的iodata,请使用
io:put_chars/1,2