Strcat returning error

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <sstream>

#include "vex.h"
#include "v5.h"
#include "v5_vcs.h"

std::string test = "Test"
std::string temp = "Temp"

strcat(test, temp);

Returns the following error:

[clang] No matching function for call to 'strcat'

But

 strcat("Test", "Temp");

Returns no error

1 Like

strcat is a function for c strings, this is char *. The class std::string is different, but it has all these operations built-in. This means it can be done like this…

test += temp;

The reason the other line of code worked is because "Test" is string literal[1] [2] and it gets evaluated to const char *, which strcat does except.

Also, this might be important at some point if you are using strings, .c_str() returns a char * of the string.

1 Like

Try to avoid using this - it’s a common source of memory permission errors and similar issues. Generally speaking, you can use C++ strings for everything in VEXCode.

2 Likes