簡體   English   中英

Ubuntu 13.10中的GCC iostream fstream錯誤

[英]GCC iostream fstream error in Ubuntu 13.10

我正在使用Ubuntu 13.10。 我在以下代碼中遇到一些錯誤。

#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>

int main(int argc, char *argv[])
{
    error.set_program_name(argv[0]);    

    if ( argc != 2 )
    {
    //  printf(argv[0] + " usage: fifo_client [string] \n");
    /// cout << argv[0] << " usage: fifo_client [string]" << endl;
        exit(EXIT_FAILURE);
    }

    ofstream out(fifo_file);
    if(out)

        out << argv[1] << endl;

    return(EXIT_SUCCESS);
}

如果我使用命令運行上述程序ac

gcc a.c -o a

a.c:1:20: fatal error: iostream: No such file or directory
 #include <iostream>
                    ^
compilation terminated.

我不知道出什么問題了。

使用g ++而不是gcc。 如果gcc具有正確的擴展名(例如.cpp)或帶有正確的參數( -x c++ ),則可以編譯c ++文件,但是添加與C ++庫鏈接所需的參數太復雜了,無法避免簡單的解決方案。

問題是您要混合使用C和C ++代碼並使用GCC對其進行編譯。

嘗試

#include <fstream>
using namespace std;

無論如何,您的源代碼並不完整,無法提出正確的建議,而不是#include <fstream.h>

我在編譯器中運行了您的代碼,並收到以下錯誤消息:-

test2.c:3:21: fatal error: fstream.h: No such file or directory
 #include <fstream.h>
                     ^
compilation terminated.

所以我認為您的問題有錯別字。

這是因為您要混合使用c和c ++代碼,所以fstream是c ++的一部分。 嘗試由g ++運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM