[英]GCC iostream fstream error in Ubuntu 13.10
I am using Ubuntu 13.10. 我正在使用Ubuntu 13.10。 I am getting some errors for the following code.
我在以下代码中遇到一些错误。
#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);
}
If I run the above program ac using command 如果我使用命令运行上述程序ac
gcc a.c -o a
a.c:1:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
I don't know whats the problem. 我不知道出什么问题了。
Use g++ instead of gcc. 使用g ++而不是gcc。 gcc could compile a c++ file if it had the right extension (.cpp for instance) or with the right arguments (
-x c++
) but adding the arguments needed to link with the C++ libraries is far too complex to avoid the simple solution. 如果gcc具有正确的扩展名(例如.cpp)或带有正确的参数(
-x c++
),则可以编译c ++文件,但是添加与C ++库链接所需的参数太复杂了,无法避免简单的解决方案。
问题是您要混合使用C和C ++代码并使用GCC对其进行编译。
try 尝试
#include <fstream>
using namespace std;
instead of #include <fstream.h>
anyway your source code is not full to make correct suggestion. 无论如何,您的源代码并不完整,无法提出正确的建议,而不是
#include <fstream.h>
。
I ran your code in my compiler and got following error :- 我在编译器中运行了您的代码,并收到以下错误消息:-
test2.c:3:21: fatal error: fstream.h: No such file or directory
#include <fstream.h>
^
compilation terminated.
so i think your question has typo. 所以我认为您的问题有错别字。
It is because you are mixing c and c++ code, fstream is part of c++. 这是因为您要混合使用c和c ++代码,所以fstream是c ++的一部分。 try to run by g++.
尝试由g ++运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.