網(wǎng)上有很多關(guān)于辦理pos機(jī)模板,使用Drogon的CSP模板生成靜態(tài)頁面的知識,也有很多人為大家解答關(guān)于辦理pos機(jī)模板的問題,今天pos機(jī)之家(m.afbey.com)為大家整理了關(guān)于這方面的知識,讓我們一起來看下吧!
本文目錄一覽:
辦理pos機(jī)模板
前言因為博客站點的服務(wù)器的,一直是單核1G內(nèi)存的配置,配置比較低,所以博文都是生成靜態(tài)頁面的,這里使用Drogon的CSP模板靜態(tài)頁面,使用還是很簡單的.生成靜態(tài)頁面的代碼不多.
{ HttpViewData data; data.insert("article", article); //將文章內(nèi)容放入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解析后的內(nèi)容,寫入靜態(tài)文件中,這里不考慮寬字符}
至于代碼中,為什么說不考慮寬字符?在前面有說到過. 使用Drogon中的CSP模板遇到的問題 ,還是比較吐槽c++的字符串很難用.
說說遇到的問題說說上面遇到的問題,就是生成的靜態(tài)頁面的文件判斷是否html后綴名.當(dāng)時有點疑惑.
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)的結(jié)果,讓我有點意外的.這一點和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可以更有語義,容易理解,應(yīng)該是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.*///中文機(jī)翻/*這是一個特殊值,等于size_type類型所能表示的最大值。確切的含義取決于上下文,但它通常被期望字符串索引的函數(shù)用作字符串結(jié)束指示符,或被返回字符串索引的函數(shù)用作錯誤指示符。*//*請注意雖然定義使用了-1,但size_type是一個無符號整型,npos的值是它能容納的最大正值,這是由于有符號到無符號的隱式轉(zhuǎn)換。這是一種指定任何無符號類型的最大值的可移植方法。*/結(jié)果
這里順便學(xué)習(xí)一下字符串的查找,其實在這里使用find,并不是很合適,這里可以find_last_of,如果使用新版本的話,是可以使用starts_with和ends_with,這兩個函數(shù)是返回值bool值.
個人能力有限,如果您發(fā)現(xiàn)有什么不對,請私信我
如果您覺得對您有用的話,可以點個贊或者加個關(guān)注,歡迎大家一起進(jìn)行技術(shù)交流
以上就是關(guān)于辦理pos機(jī)模板,使用Drogon的CSP模板生成靜態(tài)頁面的知識,后面我們會繼續(xù)為大家整理關(guān)于辦理pos機(jī)模板的知識,希望能夠幫助到大家!
![](/style/images/zhouzong.jpg)