Download presentation
Presentation is loading. Please wait.
Published byKathleen Small Modified over 8 years ago
1
Strings in C++/CLI http://msdn.microsoft.com/en- us/library/system.string.aspxhttp://msdn.microsoft.com/en- us/library/system.string.aspx public: static String^ Format( String^ format,... array ^ args ) Format:{index[,length][:formatString]} {0}, {0, 10}, {0, -10}, {0, -10:D6}
2
String^ dateString1 = "1"; String^ fmtString = String::Format("{0,10}",dateString1); // -10 to left, 10 to right Console::WriteLine(fmtString); int dateString2 = 1; String^ fmtString = String::Format("{0,-10:D6}",dateString2); Console::WriteLine(fmtString); String^ result = nullptr; result += String::Format("{0,10}", L"X4"); result += String::Format("{0, 10:D6}", dateString2); result += String::Format("{0,10}", L"end"); Console::WriteLine(result);
3
String^ result1 = L"X4"; String^ result2 = String::Format("{0} ", dateString2); String^ result3 = L"end"; Console::WriteLine("{0,10} {1, 10} {2,10}", result1, result2, result3); fmtString = String::Format("{0,10} {1, 10} {2,10}", result1, result2, result3); Console::WriteLine(fmtString); fmtString = String::Format("{0,10} {1, 10} {2,10}", result1, dateString1, result3); Console::WriteLine(fmtString);
4
files using namespace System::IO; StreamReader ^sr = gcnew StreamReader("control.txt"); this->choice=Int32::Parse(sr->ReadLine()); sr->Close();
5
Windows Form Application
6
Create a form application using Visual C++ Step 0: //Create a Windows Forms application in Visual Studio 2012 –Create an empty Form1 following “how-to-VS2012” from BBL –do not add stuffs to the empty Form1 –change Form1’s Text to “CS351”: with the “Form1.h[Design]” active, open the “Properties” window, change the existing “Form1” to “CS351” –Add (copy-paste) code from main.cpp to Form1.cpp by first clicking the Form1.cpp from the “Solution Explorer” window to open it; then modifying the namespace to be your project name; –Build and run, make sure it works
7
Cont’d I There are two approaches to try to work out the rest of the sample code, –Approach 1 is a direct copy-paste, –Approach 2 takes each step in class. Step1, Approach 1: –Copy the sample code to the Form1.h (double click Form1 in the [Design], modify the namespace to your project name. –Or, copy the sample code file Form1.h to the project directory (replace the existing file); modify the namespace to your project name. –Build and run
8
Step1, Approach 2: // read the sample code to help –Open Form1.h, by double clicking Form1 in the [Design] view –Build each specific items according to the sample code. Examples: –Add label (s), change text, sizes, variable names, etc.; check code many… –Build and run Cont’d I
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.