部分是這樣的:如何在cpp和c中不使用cout/printf輸出文本?我的cpp的代碼
void Error()
{
string line;
fperror.open("Error.txt");
while (getline (fperror,line))
{
cout << line << endl;
}
fperror.close();
return;
}
相應的C是這樣的:
void Error()
{
int c;
fperror= fopen("Error.txt", "r");
c=getc(fperror);
while(c != EOF)
{
putchar(c);
c=getc(fperror);
}
fclose(fperror);
return;
}
這是我的項目我的類,我們的教授告訴我們,我們不允許使用函數中的cout/cin或printf/scanf。所以我想知道是否可以輸出文本文件的內容而不使用cout/printf? (我們必須使用void fun(void)類型的函數)
'fread'/'fwrite'?雖然如果這是一個C++類,它是相當愚蠢的取締iostreams ... – cHao
['fgets'](http://en.cppreference.com/w/c/io/fgets),['puts'](http ://en.cppreference.com/w/c/io/puts),['fwrite'](http://en.cppreference.com/w/c/io/fwrite)等等。而且你的老師需要理解*沒有人*這樣的代碼,如果他們完全可以避免的話。不適用于格式化輸出。如果你想*原始*輸出,然後hellyas。 – WhozCraig
呃。即使對於原始輸出,C的東西相對於像std :: cout << fperror.rdbuf();' – cHao