Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) StdStrcatExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppStdStrcatExample1/CppStdStrcatExample1.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

 

 

 

 

 

./CppStdStrcatExample1/main.cpp

 

#include <cassert>
#include <cstring>

int main()
{
  const char a[] = "ABC";
  const char b[] = "DEFG";
  char * c = new char[ std::strlen(a) + std::strlen(b) + 1 ]; //+1 for null terminator
  std::strcpy(c,a);
  assert(std::strcmp(c,"ABC") == 0);
  std::strcat(c,b);
  assert(std::strcmp(c,"ABCDEFG") == 0);
  delete[] c;
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml