-
January 17th, 2011, 11:03 PM
#1
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.
-
January 18th, 2011, 06:12 AM
#2
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.
-
January 18th, 2011, 07:16 AM
#3
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.
-
January 21st, 2011, 09:33 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|