为什么C++ 11提供std::u16string和std::u32string不std::u8string?我们需要实现utf-8编码或使用其他库吗?
如何在 Visual Studio 2019(16.3 预览版 4)中启用 c++20?
我对测试一些 C++20 特性很感兴趣。
如果任何字符串包含某个单词,我需要从字符串向量中删除一些元素.
我怎样才能写出一元谓词remove_if?
这是代码示例:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
bool remove_if_found(string word)
{
// ???
}
int main()
{
vector<string> data {
{ "the guitar has six strings" },
{ "the violin has four strings" },
{ "the the violin is more difficult to learn" },
{ "saxophones are a family of instruments" },
{ "the drum is a set of percussions" },
{ "the trumpet is a brass" }
};
cout << …Run Code Online (Sandbox Code Playgroud) How can I print a range of elements (key and value) belonging to a std::map<size_t, std::string>?
I don't need to print all elements.
Every suggestion using C++11, C++14 or C++17, without boost libraries, is appreciated.
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
void print(map<size_t, string> & m)
{
for(auto & [key, value] : m)
{
cout << setw(6) << left << key << value << endl;
}
}
void print_range(map<size_t, string> & m, size_t first, size_t …Run Code Online (Sandbox Code Playgroud) 我有一个包含许多 svg 文件的文件夹,我想使用带有批处理脚本(Windows 10*.bat文件)的inkscape 将它们转换为png 文件。以下脚本适用于单个文件,但是,如何为目录中的数百个文件迭代相同的命令?
PATH = "C:\Program Files\Inkscape"
inkscape myfile.svg --export-png=myfile.png
Run Code Online (Sandbox Code Playgroud) 我尝试std::async按以下方式在成员函数内部使用:
#include <iostream>
#include <vector>
#include <string>
#include <future>
using namespace std;
class splitter
{
public:
splitter() = default;
virtual ~splitter() = default;
bool execute(vector<string> &vstr);
bool split_files(vector<string> &vstr);
};
bool splitter::split_files(vector<string> &vstr)
{
for(auto & file : vstr)
{
// do something
cout << file << endl;
}
return true;
}
bool splitter::execute(vector<string> &vstr)
{
auto fut = std::async(std::launch::async, split_files, vstr);
bool good = fut.get();
return good;
}
int main()
{
vector<string> filenames {
"file1.txt",
"file2.txt",
"file3.txt" …Run Code Online (Sandbox Code Playgroud)