I've recently started using Microsoft Visual Studio Code on my Windows PC and integrated the terminal with it to run/debug C/C++ programs (reference: How to Write And Run C and C++ Code in Visual Studio Code).
However, while executing certain programs, I'm getting compilation error messages such as below:
'mbrtoc16' has not been declared in '::'
'c16rtomb' has not been declared in '::'
'mbrtoc32' has not been declared in '::'
'c32rtomb' has not been declared in '::'
May I get help on fixing these, please? I get the errors while debugging/running the below C++ program in VS Code:
#include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
vector<int> freqQuery(vector<vector<int>> queries) {
int index=0, choice, value, flag;
vector<int> result;
unordered_map<int,int> contents;
unordered_map<int,int> :: iterator content_itr;
vector<vector<int>> :: iterator query_itr = queries.begin();
while(query_itr < queries.end()){
choice = query_itr[0][0];
value = query_itr[0][1];
flag = -1;
if(choice == 1){
content_itr = contents.find(value);
if(content_itr == contents.end())
contents.insert(make_pair(value, 1));
else
content_itr->second += 1;
}
else if(choice == 2) {
content_itr = contents.find(value);
if(content_itr != contents.end())
content_itr->second -= 1;
}
else if (choice == 3){
for(content_itr = contents.begin(); content_itr != contents.end(); content_itr++)
if(content_itr->second == value){
flag=1;
break;
}
if(flag == 1)
result.push_back(1);
else
result.push_back(0);
}
query_itr++;
}
return result;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string q_temp;
getline(cin, q_temp);
int q = stoi(ltrim(rtrim(q_temp)));
vector<vector<int>> queries(q);
for (int i = 0; i < q; i++) {
queries[i].resize(2);
string queries_row_temp_temp;
getline(cin, queries_row_temp_temp);
vector<string> queries_row_temp = split(rtrim(queries_row_temp_temp));
for (int j = 0; j < 2; j++) {
int queries_row_item = stoi(queries_row_temp[j]);
queries[i][j] = queries_row_item;
}
}
vector<int> ans = freqQuery(queries);
for (int i = 0; i < ans.size(); i++) {
fout << ans[i];
if (i != ans.size() - 1) {
fout << "\n";
}
}
fout << "\n";
fout.close();
return 0;
}
string ltrim(const string &str) {
string s(str);
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
);
return s;
}
string rtrim(const string &str) {
string s(str);
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
s.end()
);
return s;
}
vector<string> split(const string &str) {
vector<string> tokens;
string::size_type start = 0;
string::size_type end = 0;
while ((end = str.find(" ", start)) != string::npos) {
tokens.push_back(str.substr(start, end - start));
start = end + 1;
}
tokens.push_back(str.substr(start));
return tokens;
}
One way I could figure out to suppress those errors is by commenting out the the line #include <cuchar>
in the header file named stdc++.h
. However, I believe this is just a workaround that might impact something else possibly, and not an absolute solution.