辦理pos機模板,使用Drogon的CSP模板生成靜態(tài)頁面

 新聞資訊2  |   2023-07-04 09:26  |  投稿人:pos機之家

網上有很多關于辦理pos機模板,使用Drogon的CSP模板生成靜態(tài)頁面的知識,也有很多人為大家解答關于辦理pos機模板的問題,今天pos機之家(www.dsth100338.com)為大家整理了關于這方面的知識,讓我們一起來看下吧!

本文目錄一覽:

1、辦理pos機模板

辦理pos機模板

前言

因為博客站點的服務器的,一直是單核1G內存的配置,配置比較低,所以博文都是生成靜態(tài)頁面的,這里使用Drogon的CSP模板靜態(tài)頁面,使用還是很簡單的.生成靜態(tài)頁面的代碼不多.

{ HttpViewData data; data.insert("article", article); //將文章內容放入HttpViewData中 data.insert("categoryList", categoryList); //將文章類別放入HttpViewData中 auto htmlTemplate = HttpResponse::newHttpViewResponse("htmlTemplate", data); //使用csp模板 string htmlName; //生成靜態(tài)頁面的名稱 htmlName.reserve(64); htmlName.append(app().getDocumentRoot()); //這里為站點指定的根目錄 htmlName.append("articles/"); htmlName.append(filename); //*********這里遇到點小問題 std::ofstream ow(htmlName, std::ios::binary); // ow << htmlTemplate->getBody(); //獲取csp解析后的內容,寫入靜態(tài)文件中,這里不考慮寬字符}

至于代碼中,為什么說不考慮寬字符?在前面有說到過. 使用Drogon中的CSP模板遇到的問題 ,還是比較吐槽c++的字符串很難用.

說說遇到的問題

說說上面遇到的問題,就是生成的靜態(tài)頁面的文件判斷是否html后綴名.當時有點疑惑.

std::string str = "123";auto p = str.find(".html");int pp = str.find(".html");std::cout << "p=" << p << std::endl; // 猜猜p的值是多少?std::cout << "pp=" << pp << std::endl; // 猜猜p的值是多少?

使用auto接收字符串的find方法返回值?猜猜是多少?

因為使用auto比較方便,所以在auto自動識別返回值類型,但出現(xiàn)的結果,讓我有點意外的.這一點和C#/JavaScript的IndexOf方法不太一樣,這兩個語言查找不到的話,返回值為-1 .后面去查看string find文檔,發(fā)現(xiàn)find返回值類型要使用的std::string::size_type.查找不到的話要和std::string::npos是否相等.

//c++ string find文檔地址//https://en.cppreference.com/w/cpp/string/basic_string/find

看一下npos是如何定義的:

static constexpr auto npos{static_cast<size_type>(-1)}; //npos的值還是-1

所以不使用string類型下的size_type,使用int也是可以的,只是使用npos可以更有語義,容易理解,應該是no pos吧.來來文檔的解釋:

static const size_type npos = -1;/* This is a special value equal to the maximum value representable by the type size_type. The exact meaning depends on context, but it is generally used either as end of string indicator by the functionsthat expect a string index or as the error indicator by the functions that return a string index.*//* NoteAlthough the definition uses -1, size_type is an unsigned integer type,and the value of npos is the largest positive value it can hold, due to signed-to-unsigned implicit conversion. This is a portable way to specify the largest value of any unsigned type.*///中文機翻/*這是一個特殊值,等于size_type類型所能表示的最大值。確切的含義取決于上下文,但它通常被期望字符串索引的函數(shù)用作字符串結束指示符,或被返回字符串索引的函數(shù)用作錯誤指示符。*//*請注意雖然定義使用了-1,但size_type是一個無符號整型,npos的值是它能容納的最大正值,這是由于有符號到無符號的隱式轉換。這是一種指定任何無符號類型的最大值的可移植方法。*/結果

這里順便學習一下字符串的查找,其實在這里使用find,并不是很合適,這里可以find_last_of,如果使用新版本的話,是可以使用starts_with和ends_with,這兩個函數(shù)是返回值bool值.

個人能力有限,如果您發(fā)現(xiàn)有什么不對,請私信我

如果您覺得對您有用的話,可以點個贊或者加個關注,歡迎大家一起進行技術交流

以上就是關于辦理pos機模板,使用Drogon的CSP模板生成靜態(tài)頁面的知識,后面我們會繼續(xù)為大家整理關于辦理pos機模板的知識,希望能夠幫助到大家!

轉發(fā)請帶上網址:http://www.dsth100338.com/newsone/79561.html

你可能會喜歡:

版權聲明:本文內容由互聯(lián)網用戶自發(fā)貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權/違法違規(guī)的內容, 請發(fā)送郵件至 babsan@163.com 舉報,一經查實,本站將立刻刪除。