‘壹’ C++濡备綍璇诲叆涓涓鏂囦欢涓镄勭粨鏋勪綋鏁扮粍鏁版嵁锛
鍙栧喅浜庢枃浠朵腑鏁版嵁镄勫瓨鍌ㄦ柟寮忋
1 濡傛灉鏂囦欢涓瀛桦偍镄勬柟寮忎负浜岃繘鍒跺舰寮忔暟鎹锛
闇瑕佷娇鐢╢read锛圕璇瑷椋庢牸锛夋垨ifsteam镄剅ead鎴愬憳鍑芥暟(C++椋庢牸銆)浠庢枃浠朵腑璇诲彇缁撴瀯浣撴暟鎹鍒板瑰簲镄勭粨鏋勪綋鎸囬拡涓娿
濡
struct test
{
int a;
};
struct test t;
fread(&t, 1,sizeof(t), fp);
鎴
file.read(&t, sizeof(t));
2 濡傛灉鏂囦欢涓锛屾槸浠ユ枃链鏂瑰纺瀛桦偍镄勫彲璇荤殑缁撴瀯浣撴暟鎹锛
闇瑕佹牴鎹鏂囦欢涓鏁版嵁镄勫瓨鍌ㄦ牸寮忥纴阃氲繃fscanf锛圕璇瑷椋庢牸锛夋垨ifstream镄>>鎴愬憳鍑芥暟锛岃诲彇钖勪釜鍊煎埌瀵瑰簲镄勭粨鏋勪綋鎴愬憳鍙橀噺涓銆
濡 struct test t;
fscanf(fp, "%d",&t.a);
鎴
file>>t.a;