專案設定

image

Common Language Runtime Support預設值為No Common Language Runtime Support

改選擇支援Common Language Runtime(/clr)

image

設定clr完成後編輯程式才會自動出現對應的提示字,否則會不認得namespace System及System::IO

   1: // WriteFileDemo4.cpp : Defines the entry point for the console application.
   2: //
   3:  
   4: #include "stdafx.h"
   5: using namespace System;
   6: using namespace System::IO;
   7:  
   8: int _tmain(int argc, _TCHAR* argv[])
   9: {
  10:     // 寫入檔案
  11:     String^ path = "test.txt";
  12:     StreamWriter^ sw = File::CreateText(path);
  13:     String^ line = "我要寫入4";
  14:     sw->WriteLine(line);
  15:     sw->Close();
  16:  
  17:     // 讀取檔案
  18:     StreamReader^ sr = File::OpenText(path);
  19:     String^ s = "";
  20:     if( s = sr->ReadLine())
  21:     {
  22:         Console::WriteLine( s );
  23:     }
  24:     Console::ReadLine();
  25:     return 0;
  26: }
arrow
arrow
    全站熱搜

    me1237guy 發表在 痞客邦 留言(0) 人氣()