| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「VC++.NET」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
(ページの作成:「==基本== ===ポインタ と new と null=== StreamWriter^ pwriter = nullptr; pwriter = gcnew StreamWriter("C:\\KBTest.txt"); ===ファイルの読み書き===…」)
 
6行目: 6行目:
 
===ファイルの読み書き===
 
===ファイルの読み書き===
 
====ファイルを読む====
 
====ファイルを読む====
  listBox1->Items->Clear();
+
  listBox1->Items->Clear();
 
  try {
 
  try {
 
     String^ textFile = String::Concat(windir,"\\mytest.txt");
 
     String^ textFile = String::Concat(windir,"\\mytest.txt");
12行目: 12行目:
 
     do
 
     do
 
     {
 
     {
         listBox1->Items->Add(reader->ReadLine());
+
         listBox1->Items->Add(reader->ReadLine());
 
     }
 
     }
     while(reader->Peek() != -1);
+
     while(reader->Peek() != -1);
 
  }
 
  }
 
  catch(FileNotFoundException^ ex)
 
  catch(FileNotFoundException^ ex)
 
  {
 
  {
     listBox1->Items->Add(ex);
+
     listBox1->Items->Add(ex);
 
  }
 
  }
 
  catch(System::Exception^ e)
 
  catch(System::Exception^ e)
 
  {
 
  {
     listBox1->Items->Add(e);
+
     listBox1->Items->Add(e);
 
  }
 
  }
 
====ファイルに書く====
 
====ファイルに書く====
 
  StreamWriter^ pwriter = gcnew StreamWriter("C:\\KBTest.txt");
 
  StreamWriter^ pwriter = gcnew StreamWriter("C:\\KBTest.txt");
  pwriter->WriteLine("File created using StreamWriter class.");
+
  pwriter->WriteLine("File created using StreamWriter class.");
  pwriter->Close();
+
  pwriter->Close();
  listBox1->Items->Clear();
+
  listBox1->Items->Clear();
 
  String ^filew = gcnew String("File Written to C:\\KBTest.txt");
 
  String ^filew = gcnew String("File Written to C:\\KBTest.txt");
  listBox1->Items->Add(filew);
+
  listBox1->Items->Add(filew);
 
====ファイル情報の表示====
 
====ファイル情報の表示====
  listBox1->Items->Clear();
+
  listBox1->Items->Clear();
 
  String^ testfile = String::Concat(windir,"\\notepad.exe");
 
  String^ testfile = String::Concat(windir,"\\notepad.exe");
 
  FileInfo^ pFileProps = gcnew FileInfo(testfile);
 
  FileInfo^ pFileProps = gcnew FileInfo(testfile);
 
   
 
   
  listBox1->Items->Add(String::Concat("File Name = ", pFileProps->FullName));
+
  listBox1->Items->Add(String::Concat("File Name = ", pFileProps->FullName));
  listBox1->Items->Add(String::Concat("Creation Time = ", pFileProps->CreationTime.ToString()));
+
  listBox1->Items->Add(String::Concat("Creation Time = ", pFileProps->CreationTime.ToString()));
  listBox1->Items->Add(String::Concat("Last Access Time = ", pFileProps->LastAccessTime.ToString()));
+
  listBox1->Items->Add(String::Concat("Last Access Time = ", pFileProps->LastAccessTime.ToString()));
  listBox1->Items->Add(String::Concat("Last Write Time = ", pFileProps->LastWriteTime.ToString()));
+
  listBox1->Items->Add(String::Concat("Last Write Time = ", pFileProps->LastWriteTime.ToString()));
  listBox1->Items->Add(String::Concat("Size = ", pFileProps->Length.ToString()));
+
  listBox1->Items->Add(String::Concat("Size = ", pFileProps->Length.ToString()));
  
  

2020年2月15日 (土) 08:06時点における版

基本

ポインタ と new と null

StreamWriter^ pwriter = nullptr;
pwriter = gcnew StreamWriter("C:\\KBTest.txt");

ファイルの読み書き

ファイルを読む

listBox1->Items->Clear();
try {
    String^ textFile = String::Concat(windir,"\\mytest.txt");
    StreamReader^ reader = gcnew StreamReader(textFile);
    do
    {
        listBox1->Items->Add(reader->ReadLine());
    }
    while(reader->Peek() != -1);
}
catch(FileNotFoundException^ ex)
{
    listBox1->Items->Add(ex);
}
catch(System::Exception^ e)
{
    listBox1->Items->Add(e);
}

ファイルに書く

StreamWriter^ pwriter = gcnew StreamWriter("C:\\KBTest.txt");
pwriter->WriteLine("File created using StreamWriter class.");
pwriter->Close();
listBox1->Items->Clear();
String ^filew = gcnew String("File Written to C:\\KBTest.txt");
listBox1->Items->Add(filew);

ファイル情報の表示

listBox1->Items->Clear();
String^ testfile = String::Concat(windir,"\\notepad.exe");
FileInfo^ pFileProps = gcnew FileInfo(testfile);

listBox1->Items->Add(String::Concat("File Name = ", pFileProps->FullName));
listBox1->Items->Add(String::Concat("Creation Time = ", pFileProps->CreationTime.ToString()));
listBox1->Items->Add(String::Concat("Last Access Time = ", pFileProps->LastAccessTime.ToString()));
listBox1->Items->Add(String::Concat("Last Write Time = ", pFileProps->LastWriteTime.ToString()));
listBox1->Items->Add(String::Concat("Size = ", pFileProps->Length.ToString()));


リンク

VC++.NET Express

  • VC++.NET Express
  • VC++.NET コードテンプレート
  • VC++.NET Express から Oracleへ接続

アルゴリズム

  • アルゴリズム

言語仕様

  • C++ CLI コードテンプレート 継承

Tips

IDE
  • VC++.NET イベントハンドラの追加
  • VC++.NET ToolStripの作成