Dynamic wchar_t array (C++ beginner) [closed] - c++

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am modifying some C++ code that has a wchar_t myArray[MAX_PATH] in the header file.
My modifications mean that I cannot know the length of this array until runtime. How can I store an array of dynamic length instead? Maybe I just keep a wchar_t* in the header file and another int to hold its length?

Use std::wstring instead. It's a dynamic string containing wchar_t.

Related

not declared in this scope error msg [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I gettin not declared in this scope error msg also declared .h file & EngineFactory class in .h
EngineFactory *engineFactory = NULL;
engineFactory = new EngineFactory();
EngineFactory->Create();
EngineFactory->destroy();
There is two problems in the code:
Your code is not inside a function. Place it in main() function, and it'll work better.
EngineFactory->Create(); has uppercase EngineFactory, while your variable is lowercase.

Segmentation fault while inserting into map [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am inserting 'this' pointer into a map
Does it cause a segmentation fault
My code is
client->commandHandlerMap.insert(std::pair<CommandType , CommandHandler*>(CommandType::OrderBookCommandType , this));
I am doing this inside the member function of a derived class of CommandHandler
I would assume that client is not initialized or has an invalid pointer.

Multilple template end tag [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Ogre::any_cast<std::map<Rail>::iterator>
It takes Ogre::any_cast<std::map<Rail> and says too few arguments etc. How can I fix it (other than obvious typedef aliasing)?
The problem is that std::map takes at least two template arguments - the key type and the value type. Currently you have std::map<Rail>. What are you mapping from Rail to? For example, this would be okay if your iterators are for a std::map that maps from Rail to int (assuming Rail is not a deduced type):
Ogre::any_cast<std::map<Rail,int>::iterator>(some_any_object)

Odd strncpy usage [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I've seen a pretty strange (for me) usage of this method:
strncpy(somePointer,"%d",someInt);
What does this actually do? The integer specifier "%d" as the source is troublesome for me to understand.
It does what it says on the tin: It copies the literal string "%d" into a char buffer pointed to by somePointer, or at least the first someInt bytes of it (up to three).
Don't be upset by a percentage sign, it's just another character...

What's wrong with this code [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Somebody told me that this piece of code has some serious issues but I have not been able to get my head around such issues. Can you guys please educate me on this?
static char BASED_CODE szFilter[] = "HTML Files (*.xls)|*.xls|All Files (*.*)|*.*||";
const char* filter = "HTML Files (*.xlsx)|*.xlsx|All Files (*.*)|*.*||";
size_t length = strlen(filter);
strcpy_s(szFilter, length + 1, filter);
Well, the buffer overrun leaps out at me – szFilter isn't big enough to receive filter.
Why not use std::string since you are using C++? That makes these issues vanish.
The second parameter of strcpy_s() should be the size of the destination buffer; you've given it the size of the input string.
But as you're working in C++, you should avoid strcpy() (etc.) entirely, and use std::string.
szFilter is shorter than filter, so there is not enough place to copy filter to szFilter. You current code has undefined behaviour.