#include "stdafx.h"
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
int apple,oranges,fruit;
apple=5; oranges=6;
fruit=apple+oranges;
Console::WriteLine(L"\nOranges are not the only fruit...");
Console::Write(L"- and we have ");
Console::Write(fruit);
Console::Write(L" fruits in all\n");
int packageCount=25;
double packageWeight=2.5;
// 第一个参数,F2表示精确到小数点后两位,L表示每个字符占两个字节
Console::WriteLine(L"There are {0} packages weighing {1:F2} pounds",
packageCount,packageWeight);
Console::WriteLine(L"There are {1} packages weighing {0} pounds",
packageCount,packageWeight);
Console::WriteLine(L"There are {0,3} packages weighing {1,5:F2} pounds",
packageCount,packageWeight);
double carpetPriceSqyd=27.95;
double roomWidth=13.5;
double roomLength=24.75;
const int feetPerYard=3;
double roomWidthYds=roomWidth/feetPerYard;
double roomLengthYds=roomLength/feetPerYard;
double carperPrice=roomWidthYds*roomLengthYds*carpetPriceSqyd;
Console::WriteLine(L"Room size is {0:F2} yards by {1:F2} yards",
roomLengthYds,roomWidthYds);
Console::WriteLine(L"Room area is {0:F2} square yards",
roomLengthYds*roomWidthYds);
Console::WriteLine(L"Carpet price is ${0:f2}",carperPrice);
// ^表示line是String对象的引用,从命令行读取一整行
Console::WriteLine(L"\ninput a string:");
String^ line=Console::ReadLine();
Console::WriteLine(line);
// Console::WriteLine(L"\ninput a char:");
// char ch=Console::Read(); // 读取单个字符
// Console::WriteLine(ch);
// Console::Write(L"input a char");
// ConsoleKeyInfo keyPress=Console::ReadKey(true); // true表示不知命令行上显示
// Console::WriteLine(L"The key press corresponds to the character:{0}",
// keyPress.KeyChar);
Console::Write(L"Enter an integer:");
// Parse()函数将含有整数的字符串转换为32位整数
int value=Int32::Parse(Console::ReadLine());
Console::WriteLine(L"You entered {0}",value);
double var1=10.5,var2=12.5;
int nSum=safe_cast<int>(var1)+safe_cast<int>(var2);
Console::WriteLine(L"sum is {0}",nSum);
Console::ReadLine();
return 0;
}