名稱空間
變體
操作

std::fputs

來自 cppreference.com
< cpp‎ | io‎ | c
 
 
 
 
定義於標頭檔案 <cstdio>
int fputs( const char* str, std::FILE* stream );

將空終止字串 str 中的每個字元寫入輸出流 stream,如同重複執行 std::fputc

str 中的終止空字元不會被寫入。

目錄

[編輯] 引數

str - 要寫入的空終止字元字串
stream - 輸出流

[編輯] 返回值

成功時,返回非負值。

失敗時,返回 EOF 並設定 stream 上的錯誤指示器(參見 std::ferror)。

[編輯] 注意

相關的函式 std::puts 會在輸出末尾附加一個換行符,而 std::fputs 則按原樣寫入字串。

不同的實現會返回不同的非負數:有些返回寫入的最後一個字元,有些返回寫入的字元數(如果字串比該值長,則返回 INT_MAX),有些則只返回一個非負常量,例如零。

[編輯] 示例

#include <cstdio>
 
int main(void)
{
    int rc = std::fputs("Hello World", stdout);
 
    if (rc == EOF)
        std::perror("fputs()"); // POSIX requires that errno is set
}

輸出

Hello World

[編輯] 參見

將格式化輸出列印到 stdout、檔案流或緩衝區
(函式) [編輯]
stdout 寫入一個字串
(函式) [編輯]
向檔案流寫入一個寬字串
(函式) [編輯]
從檔案流獲取字元字串
(函式) [編輯]
C 文件 關於 fputs