I'm trying to use strcpy_s, but i get another error dealing with the size, saying : L "Buffer is too small && 0"
when i try to run the program, and i dont know ifsizeof tochar
from strcpy_s(tochar, sizeof tochar, test.c_str());
is correct because I keep getting this error.
Full compiling code:
#include "stdafx.h"
#include <string>
#include <string.h>
#include <cstring>
#include <stdlib.h>
#include <errno.h>
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
#include <iomanip>
#include <stdio.h>
using namespace std;
using std::vector;
using std::string;
int main()
{
std::string test;
std::vector<std::string> v3 = { "filename1", "filename2","filename3", };
for (int m = 0; m < v3.size(); m++) {
test = "\"" + v3[m] + ".txt" + "\"";
char * tochar = new char[test.length() + 1];
strcpy_s(tochar, sizeof tochar, test.c_str());
std::cout << tochar << std::endl;
}
return 0;
}
I cant use strcpy
in c++ 2015, i have to use strcpy_s
now because strcpy
gives a different error, and i dont want to just turn off the error. (unless there is some sort of code i can put in the program that will let it compile with strcpy
)
I want the tochar
to output: "filename1.txt"