Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbccb85b

Browse files
committed
#205-test method CppStringT::format()
Completed. Validated.
1 parent18f4f7d commitbccb85b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

‎cpp-strings-tests/cpp-strings-tests.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,26 @@ namespace cppstringstests
25412541

25422542
}
25432543

2544+
TEST_METHOD(format)
2545+
{
2546+
pcs::CppString s;
2547+
s.format("{:d}, {:d}, {:s}",1,2,"Abc");
2548+
Assert::AreEqual("1, 2, Abc", s.c_str());
2549+
2550+
constint x{5 };
2551+
constunsignedlonglong y{6 };
2552+
constdouble pi{3.141592653529 };
2553+
const std::string t{"abc." };
2554+
Assert::AreEqual("56 3.1415927abc.", (s.format("{}{}{:10.7f}{:s}", x, y, pi, t)).c_str());
2555+
2556+
pcs::CppWString ws;
2557+
ws.format(L"{:d}, {:d}, {}",1,2,L"Abc");
2558+
Assert::AreEqual(L"1, 2, Abc", ws.c_str());
2559+
2560+
const std::wstring wt{L"abc." };
2561+
Assert::AreEqual(L"56 3.1415927abc.", (ws.format(L"{}{}{:10.7f}{:s}", x, y, pi, wt)).c_str());
2562+
}
2563+
25442564
TEST_METHOD(index_char)
25452565
{
25462566
using string_type = pcs::CppString;

‎cpp-strings/cppstrings.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ using namespace pcs;
2929
*/
3030
intmain()
3131
{
32-
CppString s ="-5.1";
32+
CppString s ="-5.1"cs;
3333
CppWString ws{L"-5.2"cs };
3434

3535
std::cout << ws.isupper() << std::endl;
3636
std::cout << s.zfill(10).c_str() << std::endl;
3737

38+
s.format("{} {}",1,3.14);
39+
ws.format(L"{} abc",2);
40+
41+
std::cout << s.c_str() <<" /";
42+
std::wcout << ws.c_str() << std::endl;
43+
3844
return0;
3945
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp