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);