/*楼上的题目会误人子弟的,这样肯定没法过关,下面的才可以!*/
#include
#include
#include
#define szBUF 256
int main(int argc, char * argv[])
{
char filename[szBUF], buf[szBUF]; int r = 0; FILE * f = 0;
if(argc < 2) {
printf("please input the file name:");
gets(filename);
}else
strcpy(filename, argv[1]);
//end if
f = fopen(filename, "r");
if(!f) {
printf("file %s open fault!\n", filename);
return 0;
}//end if
while(!feof(f)) {
r = fread(buf, sizeof(char), szBUF, f);
if(r < 1) break;
fwrite(buf, sizeof(char), r, stdout);
}//end while
fclose(f);
system("pause");
return 0;
}
#include
using namespace std;
int main() {
freopen("text.txt","r",stdin);
char str[1024];
cin >> str;
cout << str;
system("pause");
return 0;
}
简单可行……
#include
#include
void main ( void )
{
char fileName[] = "file_to_be_read.txt";
char cmd[1024];
sprintf ( cmd, "type \"%s\"", fileName );
system ( cmd );
}