读书人

linux gcc时出现读写文件的error解决办

发布时间: 2012-04-01 17:23:46 作者: rapoo

linux gcc时出现读写文件的error
m.c:14: error: expected declaration specifiers or ‘...’ before string constant
m.c:14: error: expected declaration specifiers or ‘...’ before string constant
m.c:14: error: expected declaration specifiers or ‘...’ before ‘stdin’
m.c:14: warning: data definition has no type or storage class
m.c:14: error: conflicting types for ‘freopen’
/usr/include/stdio.h:255: note: previous declaration of ‘freopen’ was here
m.c:15: error: expected declaration specifiers or ‘...’ before string constant
m.c:15: error: expected declaration specifiers or ‘...’ before string constant
m.c:15: error: expected declaration specifiers or ‘...’ before ‘stdout’
m.c:15: warning: data definition has no type or storage class
m.c:15: error: conflicting types for ‘freopen’
/usr/include/stdio.h:255: note: previous declaration of ‘freopen’ was here

我的14,15行是

freopen("sample_data.in","r",stdin);
freopen("sample_data.out","w",stdout);


[解决办法]
这两行应该放在函数体内
freopen("sample_data.in","r",stdin);
freopen("sample_data.out","w",stdout);

读书人网 >UNIXLINUX

热点推荐