VC++ .NET 实例

#include "stdafx.h"
#include<iostream>
#include <stack>
#include <queue>
using namespace std;
using namespace System;
using namespace System::IO;
   

int main(array<System::String ^> ^args)
{
	cout<<"helloworld";
    Console::WriteLine(L"Hello World");

	// 创建堆栈对象
      stack<int> s;
      // 元素入栈
     s.push(3);
     s.push(19);
     s.push(23);
     s.push(36);
     s.push(50);
     s.push(4);
 
    // 元素依次出栈
     while(!s.empty())
     {
        // 打印栈顶元素,打印出:4 50 36 23 19 3
         cout << s.top() << endl;
         // 出栈
         s.pop();
    }


	  // 创建 queue 对象
      queue<int> q;
     // 元素入队
     q.push(3);
     q.push(19);
     q.push(29);
     q.push(26);
     q.push(33);
     // 元素出对
     while (!q.empty())
     {
         // 打印队首元素(取队首)
         cout << q.front() << '    ';
         // 删除队首元素
         q.pop();
     }
 
     cout << endl;






	String^ path = "d:\\temp\\MyTest.txt";
   if (  !File::Exists( path ) )
   {

      // Create a file to write to.
      StreamWriter^ sw = File::CreateText( path );
      try
      {
         sw->WriteLine( "Hello" );
         sw->WriteLine( "And" );
         sw->WriteLine( "Welcome" );
      }
      finally
      {
         if ( sw )
                  delete (IDisposable^)(sw);
      }
   }

   // Open the file to read from.
   StreamReader^ sr = File::OpenText( path );
   try
   {
      String^ s = "";
      while ( s = sr->ReadLine() )
      {
         Console::WriteLine( s );
      }
   }
   finally
   {
      if ( sr )
            delete (IDisposable^)(sr);
   }

   try
   {
      String^ path2 = String::Concat( path, "temp" );

      // Ensure that the target does not exist.
      File::Delete( path2 );

      // Copy the file.
      File::Copy( path, path2 );
      Console::WriteLine( "{0} was copied to {1}.", path, path2 );

      // Delete the newly created file.
      File::Delete( path2 );
      Console::WriteLine( "{0} was successfully deleted.", path2 );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The process failed: {0}", e );
   }


	system("pause");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值