c++,cstringRelated issues-Collection of common programming errors
Tom Wijsman
c++ source-check
Do you think that the criticisms in Frequently Questioned Answers are accurate?
MichaelT
design c++ logging
Recently my team has programmed a custom developer console in a video game which can easily be hidden or displayed, because it’s more comfortable and less of a hassle.The Console class contains a log(string) function which should be easily accessible from anywhere outside of it, without having to reference it everywhere.How could we design a method that can be easily accessed from the outside of the class? For example printing a message to the console in C++ is as simple as:cout << “Messag
Lex
c++ debugging error-handling assertions
I am a big fan of writing assert checks in C++ code as a way to catch cases during development that cannot possibly happen but do happen because of logic bugs in my program. This is a good practice in general.However, I’ve noticed that some functions I write (which are part of a complex class) have 5+ asserts which feels like it could potentially be a bad programming practice, in terms of readability and maintainability. I think it’s still great, as each one requires me to think about pre- and p
luk32
c++ design-patterns logging design
Hi I have fairly complex program that is doing computations in a quite large loop. I want to log some basic statistic about the run to be able to analyze its performance over time and vs loop number. For now I am outputting a set of numbers, about 5 or 6, each loop.The problem is the number of loops is quite large so the log files are big. Also putting 10^6 of measurement points on a plot is kind of pointless.I thought of “filtering” the results by for example printing every 1k’th loop but I wou
Potatoswatter
c++ design design-patterns
I have this existing code where they have a class and an initialization method in that class. It is expected that once the object of the class is created, they need to call initialize on it.Reason why the initialize method exist The object gets created early to have a global scope and then the initialize method gets called later after loading a dll which it depends on.Issue with having the initialize The class now has this bool isInitialized which needs to be checked in every method before it p
m_goldberg
mathlink c++
I am trying to create a GUI using Microsoft Visual Studio C++ 2010 by calling Mathematica in my codes. I have done everything step by step as mentioned hereThen I wrote this code as mentioned in hereThe code is as below#include <mathlink.h> #include <stdio.h>int main(int argc, char *argv[]) {MLENV env;MLINK link;int errno;env = MLInitialize(0);link = MLOpenArgcArgv(env, argc, argv, &errno);MLActivate(link);return 0; }The error I get is:1>—— Build started: Project: mathemat
Tetrad
c++ geometry allegro win32
I get the following error(s) on my program that captures the mouse and then draws a line. Errors:1>—— Build started: Project: Capture_Mouse_Line, Configuration: Debug Win32 —— 1> main.cpp 1>main.obj : error LNK2001: unresolved external symbol “public: static long * Line::yc2” (?yc2@Line@@2PAJA) 1>main.obj : error LNK2001: unresolved external symbol “public: static long * Line::xc2” (?xc2@Line@@2PAJA) 1>main.obj : error LNK2001: unresolved external symbol “public: static l
sm4
c++ opengl sdl
So I’m trying to write a simple application with SDL 1.2 and OpenGL. This a stripped down version of the code containing the one problem I’m having.//The headers #include “SDL.h” #include “SDL_opengl.h”//Screen attributes const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32;//Event handler SDL_Event event;bool initGL() {//Initialize Projection MatrixglMatrixMode( GL_PROJECTION );glLoadIdentity();//Initialize Modelview MatrixglMatrixMode( GL_MODELVIEW );glLoadIde
user1640736
c++ fbx
I need to import a complex fbx model into C++. By complex I mean that it has a lot of vertices,cameras and so on.As far as I saw this is done using the ViewScene sample.I want to take that sample and make a new project but it gives me some linking errors such as:1> main.cpp 1>main.obj : error LNK2019: unresolved external symbol “public: __thiscall SceneContext::SceneContext(char const *,int,int,bool)” (??0SceneContext@@QAE@PBDHH_N@Z) referenced in function _main 1>main.obj : error
Michael Dorst
arduino c++
Why can’t I use std::string or any other objects from the C++ Standard Library in my sketches for Arduino? #include <string> doesn’t throw an error, so it clearly has no trouble finding the libraries, but actually using anything from it does. If I writestd::string str;I get’string’ is not a member of ‘std’Why?
Soo Wei Tan
c++ vector cstring std-pair
I have a private attribute in a class that is defined as vector<pair<char *, int> > data;. I add data to this vector with data.push_back(make_pair(p, r));. Later when I go to get the data out of the vector I get bad data for the p value. The data returned is like ??U3. I think this is because a pointer to the char array is being stored. How would I go about storing an actual copy in the vector. If it helps the char array will never exceed 255 chars + 1 for null terminating.
YS Bhai
c++ cstring
I am initializing array with 99 in all the elememts#include<iostream> #include<cstring> int main(){int a[10];memset(a,99,10);std::cout<<a[0]<<std::endl;return 0; }but the output I am getting is unexpected.Output:-1667457891What is the reason behind the abnormal behavior of this memset function.
Natalie Carr
c++ cstring
I currently using C string headers and C++ and have hit a problem. I have a long path:C:\bla\bla\bla\blaI need to change the backslashes to double backslashes so that my OS_CopyFile() function can read it properly but I don’t know how?I get my path using:CHAR* szValueBuf = NULL; DWORD cchValueBuf = 0; UINT uiStat = MsiGetProperty(hInstall, TEXT(“OriginalDatabase”), TEXT(“”), &cchValueBuf);if (ERROR_MORE_DATA == uiStat) {++cchValueBuf; szValueBuf = new TCHAR[cchValueBuf];if (szValueBuf){uiSt
Romain
c++ arrays cstring
Question is in the title, how do I initialize a char*[] and give values to it in C++, thank you.
quandrum
c++ arrays pointers cstring
Ok, this is for homework about hashtables, but this is the simple stuff I thought I was able to do from earlier classes, and I’m tearing my hair out. The professor is not being responsive enough, so I thought I’d try here.We have a hashtable of stock objects.The stock objects are created like so:stock(“IBM”, “International Business Machines”, 2573, date(date::MAY, 23, 1967))my constructor looks like:stock::stock(char const * const symbol, char const * const name, int sharePrice, date priceDate):
Himilou
visual-c++ stackoverflow cstring tchar
so somewhere along the lines of putting this app together I’ve started to get a runtime check failure stack corruption when the destructor for a cstring class member is called. I’ve gotten to the point of trying to debug this by throwing bricks at the issue but still havent root caused it. At the current moment the class that the cstring resides in does nothing but initialize its private string members and set a pointer to another class to NULL.Interestingly if I do not set the class pointer to
user157704
c memory-management cstring
This code compiles fine but give segmentation fault error while running? Can anyone tell why?#include <stdio.h> #include <string.h> #include <math.h>int main() {const char s2[] = “asdfasdf”;char* s1;strcpy(s1, s2);printf(“%s”, s1);return 0; }
Brian T Hannan
c++ string-formatting cstring
LRESULT CFlashWnd::OnScannerProgress( WPARAM wParam, LPARAM lParam ) {ScannerProgress *pEvent = (ScannerProgress *)wParam;CString scannerAreaText = _T(“”);scannerAreaText.Format(_T(“<B>Scanning%3A</B> <font face=’Arial’ size=’10’>%s</font>”), pEvent->pszScanner);CString scanProgressText = _T(“”);scanProgressText.Format(_T(“<B>Scan Progress%3A</B> <font face=’Arial’ size=’10’>%f</font>”), pEvent->dwScanPercent);CString scanProgressBarValue = _
moooeeeep
c++ concatenation cstring
When I run this, I get no errors, but the string does not get concatenated. Could someone tell me what I’m getting wrong here.char *con(const char str[], int n) {char * t = new char[60];int l = strlen(str);t[l] = ‘\0’;if (n <= 0) {return t;} else {for (int i = 0; i < n; i++) {strcat(t, str);}return t;} }If I try and take out the:int l = strlen(str); t[l] = ‘\0’;Then the program crashes.
ArsenMkrt
c# c++ dll dllimport cstring
Hello Most excellent StackoverflowiansUsing visual studio 2008 Team System, I have a c++ dll (mfc statically linked regular dll) which has a simple functionextern “C” __declspec(dllexport) int MyExportedFunction( ) {AFX_MANAGE_STATE(AfxGetStaticModuleState( ))CString tempString ; …. }The DLLImport from the c# application tothe dll works and i can step inside this function from the debugger from my c# code However (yes here it comes!) inside the function “MyExportedFunction” , as you can see i
Web site is in building