Simple Pointer issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Simple Pointer issue

  1. #1
    Join Date
    Jan 2011
    Posts
    8

    Question Simple Pointer issue

    Hello,

    New to c++ and windows programming.

    int Current_Amount_Of_Groups = 1;
    wchar_t *Group_Name = "Name";

    a) wchar_t buf[30];

    b) wchar_t *buf= new wchar_t[30];

    swprintf_s( buf, 30, L"%i", Current_Amount_Of_Groups );
    wcsncat_s( buf, Group_Name),10);

    When I use a) the wsprintf_s and wcsncat_s functions work fine, but when I use b) the swprintf_s works and wcsncat_s does not.

    My issue:
    I thought by using a) and inputting buf to wcsncat_s was inputting a pointer to an array. So why am I having an issue using b) by inputting a pointer to an array? see my problem?

    P.S compiler says: No Instance of overloaded function "wcsncat_s" matches the argument list.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,062

    Re: Simple Pointer issue

    Just like the compiler said, there is no version of wcsncat_s that accepts those arguments. You have the following 2 versions:
    Code:
    errno_t wcsncat_s(
       wchar_t *strDest,
       size_t numberOfElements,
       const wchar_t *strSource,
       size_t count 
    );
    and
    Code:
    template <size_t size>
    errno_t wcsncat_s(
       wchar_t (&strDest)[size],
       const wchar_t *strSource,
       size_t count 
    );
    You are trying to use the second version, but that only works with array defined at compile time.
    For your dynamic array, you need to use the first version.

    On a side note: If you are new to C++ programming, I would highly recommend to forget about those C-style ways of working with strings and switch to the C++ style of doing strings Use classes like std::string and std::stringstream.

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is online now Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: Simple Pointer issue

    A note aside the Marc side note .
    You can also use CString in any console or Windows application.
    Simply include <atlstr.h> then enjoy.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    Join Date
    Jan 2011
    Posts
    8

    Re: Simple Pointer issue

    I appreciate all the responses and I will look into all these options. thanks again

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center