#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;
}
VC++ .NET 实例
最新推荐文章于 2024-12-06 13:42:35 发布