Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) StdStrncatExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppStdStrncatExample1/CppStdStrncatExample1.pro

 

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

SOURCES += main.cpp

 

 

 

 

 

./CppStdStrncatExample1/main.cpp

 

#include <cstring>
#include <iostream>

int main()
{
  const char a[] = "X";
  const char b[] = "0123456789";

  const int sz = std::strlen(b) + 1; //Show both empty and complete string
  for (int i=0; i!=sz; ++i)
  {
    char * c = new char[ std::strlen(a) + i + 1 ]; //+1 for null terminator
    std::strcpy(c,a);
    std::strncat(c,b,i);
    std::cout << c << '\n';
  }
}

/* Screen output:

X
X0
X01
X012
X0123
X01234
X012345
X0123456
X01234567
X012345678
X0123456789
Press <RETURN> to close this window...

*/

 

 

 

 

 

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