Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Руководство_по_C++_CLI.doc
Скачиваний:
4
Добавлен:
01.07.2025
Размер:
8 Мб
Скачать
☆

Int main()

{

String ^ Whatever = L"The White House";

Console::WriteLine(WhiteHouse);

return 0;

}

If your initialization spans many lines, start each with its own L. Here are examples:

using namespace System;

Int main()

{

String ^ Whatever = L"The White House"

L"1600 Pennsylvania Avenue"

L"Washington, DC";

Console::WriteLine(WhiteHouse);

return 0;

}

The strings displayed in Write() or WriteLine() also support all aspects of the String class. For this reason, you can also start a string of Write() or WriteLine() with L.

Just as you can declare a String variable in a function such as main(), you can also create a member of class as a string. To do this, simple declare the String variable in the body of the class.

7.1.4Practical Learning: Using String Variables

  1. To use a string, access the Exercise.cpp source file

  2. Declare and use the following variables:  

using namespace System;

namespace RealEstate

{

public value class CClassification

{

public:

long PropertyNumber;

int Condition;

__wchar_t Style;

};

public value class CProperty

{

public:

CClassification ^ Class;

__wchar_t TypeOfHome;

int Bedrooms;

float Bathrooms;

Byte Stories;

int YearBuilt;

double MarketValue;

};

}

int main()

{

String ^ strTitle1 = L"=//= Altair Realty =//=";

String ^ strTitle2 = L"-=- Properties Inventory -=-";

RealEstate::CProperty ^ condo = gcnew RealEstate::CProperty;

RealEstate::CClassification ^ type = gcnew

RealEstate::CClassification;

type->PropertyNumber = 697234; // Unique Number

type->Condition = 2; // Good, may need minor repair

type->Style = L'H'; // Highrise

condo->Class = type;

condo->YearBuilt = 2002;

condo->Bathrooms = 1;

condo->Stories = 18;

condo->MarketValue = 155825;

condo->Bedrooms = 2;

condo->TypeOfHome = L'C';

Console::WriteLine(strTitle1);

Console::WriteLine(strTitle2);

Console::Write("Property #: ");

Console::WriteLine(condo->Class->PropertyNumber);

Console::Write("Condition: ");

Console::WriteLine(condo->Class->Condition);

Console::Write("Style: ");

Console::WriteLine(condo->Class->Style);

Console::Write("Type of Home: ");

Console::WriteLine(condo->TypeOfHome);

Console::Write("Bedrooms: ");

Console::WriteLine(condo->Bedrooms);

Console::Write("Bathrooms: ");

Console::WriteLine(condo->Bathrooms);

Console::Write("Stories: ");

Console::WriteLine(condo->Stories);

Console::Write("Year Built: ");

Console::WriteLine(condo->YearBuilt);

Console::Write("Market Value: ");

Console::WriteLine(condo->MarketValue);

Console::WriteLine();

return 0;

}

  1. Execute the application to see the result  

=//= Altair Realty =//=

-=- Properties Inventory -=-

Property #: 697234

Condition: 2

Style: H

Type of Home: C

Bedrooms: 2

Bathrooms: 1

Stories: 18

Year Built: 2002

Market Value: 155825

  1. Close the DOS window