C++/CLI

#include "stdafx.h"


using namespace System;


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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值