Compiling codes with *_s in Visual C++ 6.0 - string

I'm trying to compile some old codes in Visual C++ 6.0. The DSW file was missing, so I'm adding all the codes into a new workspace.
I have a.cpp as follows
#include "vld.h"
#include "afx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include "b.h"
...
void function_1(char* string1)
{
char buf[2000];
strcpy_s(&buf[0], 2000, string1);
strcat_s(&buf[0], 2000, "_append");
...
}
There are other functions used such as fopen_s, strncpy_s, strncat_s in a.cpp as well.
And b.h is
#include <stdio.h>
#include <string.h>
char function_2(unsigned char * string2, int abc, int def)
{
char buf2[200];
sprintf_s(buf2, 200, "abcdef");
strcat_s(buf2, 200, "ghijkl");
}
Despite already having stdio.h and string.h, I still get the errors
'sprintf_s': undeclared identifier
'strcat_s': undeclared identifier
'strcpy_s': undeclared identifier
'fopen_s': undeclared identifier
'strncpy_s': undeclared identifier
'strncat_s': undeclared identifier
for both a.cpp and b.h.
Is there any missing settings that I've left out? Why am I getting these errors?

The _s version function were added to Visual Studio 2005. So you need use more modern Visual Studio version.

Related

RapidJson: error C2061: syntax error: identifier 'stack_'

I am using below code in my program
#include "stdafx.h"
#include "RapidJson\rapidjson.h"
#include "RapidJson\document.h"
#include "RapidJson\stringbuffer.h"
using namespace std;
using namespace rapidjson;
....
,......
Document doc;
doc.Parse(s.c_str());
When I compile I see error
rapidjson\document.h(2425): error C2061: syntax error: identifier 'stack_'
1> rapidjson\document.h(2425): note: while compiling class template member function 'bool rapidjson::GenericDocument::StartArray(void)'
1> rapidjson\reader.h(2004): note: see reference to function template instantiation 'bool rapidjson::GenericDocument::StartArray(void)' being compiled
1>
Can someone please help me to fix the issue.
Thanks
Santhi
The issue is solved by providing different order
#include "targetver.h"
#include <stdio.h>
#include <new>
#include <tchar.h>
#include <rapidjson.h>
#include <document.h>
#include <stringbuffer.h>
#include <writer.h>
#include <prettywriter.h>
#include <Windows.h>
#include <vector>

error: ‘scmp_filter_ctx’ was not declared in this scope

I am getting compilation error:error: ‘scmp_filter_ctx’ was not declared in this scope.
I have declared a seccomp filter.
scmp_filter_ctx ctx;
I have included the library #include <linux/seccomp.h>
and already installed the library libseccomp-dev using
sudo apt-get install libseccomp-dev.
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <bits/stdc++.h>
void create_sandbox(){
scmp_filter_ctx ctx;
ctx = seccomp_init(SCMP_ACT_KILL); // default action: kill
seccomp_load(ctx);
}
I managed to solve this error using the following:
Replaced #include <linux/seccomp.h> with #include <seccomp.h>
and while compiling, used g++ filename.cpp -lseccomp.
This worked for me.

Error: Function stoi Not Declared (-std=c++11 is Enabled)

I'm using Code::Blocks 16.01 on Windows 10.
I need to convert a string to an integer.
So I'm trying to use stoi, but it says it's not declared.
I have enabled -std=c++11 in compiler settings but it still gives me an error:
'stoi' was not declared in this scope
Screenshot of Code::Blocks:
The part of the code which causes the error is:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
int n,m,k;
string nmk;
ifstream test("input00.txt");
if (test.is_open())
{
getline (test,nmk,' ');
n = stoi (nmk,NULL,10);
getline (test,nmk,' ');
m = stoi (nmk,NULL,10);
getline (test,nmk, '\n');
k = stoi (nmk,NULL,10);
}
}

msvc 15.3.1 compiler issue

I have found a strange behavior (probably an issue) while trying to compile a simple application with MS VC 15.3.1 (after applying VC 2017 Upgrade 3):
#include <iostream>
#include <algorithm>
#include <string>
// compiles if commenting out the line below
#include <vector>
#include <list>
class A
{
std::string s;
public:
A(const std::string& str) : s(str)
{
}
A(A&& other)
{
// compiles if changing std::swap<std::string>() to std::swap()
std::swap<std::string>(s, other.s);
}
};
int main(int argc, char *argv[])
{
return 0;
}
the compiler emits error :
1>d:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.11.25503\include\vector(2131):
error C2039: '_Alloc': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
This code compiles without any issues with VC 15.2, VS2015 and VS2013 toolsets.

Compiling printf() without including <stdio.h>

How msvc11 can compile printf("msvc"); with only <iostream> header?
#include <iostream>
using namespace std;
int main()
{
printf("test123");
cin.get();
return EXIT_SUCCESS;
}
No error...
msvc11
For Visual Studio 2013, iostream includes istream which includes ostream which includes ios which includes xlocnum which includes cstdio which includes stdio.h. It's just standard header file spill-over.

Resources