函式
<cstdio>

puts

int puts ( const char * str );
將字串寫入標準輸出
stdout 指向的 C 字串 寫入標準輸出,並在末尾新增一個換行符('\n').

該函式開始從指定地址(str)複製,直到遇到終止空字元('\0')。此終止空字元不會被複制到流中。

請注意,puts不僅與 fputs 的不同之處在於它使用 stdout 作為目標,而且它還在末尾自動新增一個換行符(而 fputs 不會)。

引數

str
要列印的 C 字串。

返回值

成功時,返回一個非負值。
發生錯誤時,函式返回 EOF 並設定錯誤指示器ferror)。

示例

1
2
3
4
5
6
7
8
/* puts example : hello world! */
#include <stdio.h>

int main ()
{
  char string [] = "Hello world!";
  puts (string);
}

另見