[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

Share tech news, updates, or what's on your mind.

Sign up to Post

In a code part of a software that I got to update I found a the line

TypeAndTimeZone = UINT16( 1 << 12 | uint16(timeDiff/60));

timeDiff has the negative value -7200.0000

TypeAndTimeZone will get the value: 65416
What kind of numeric value is this because I expected -120.
If I will do
TypeAndTimeZone = TypeAndTimeZone * -1 I will get 120 instead of 65416.

Is 65416 a negative numeric value? Or is there an error to get this as a negative value?
0
Angular Fundamentals
LVL 12
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

I need to learn embedded software and hardware development life cycle and use it to create electronic hardware/software component.  I need to approach this job systematically.  For example, what is the order of tasks.  Probably requirements should be gathered and documented.  Then, what's next and so on?  At what stage should we select hardware components.
0
CWinThread wont exit in Release mode but will in Debug mode visual studio 2017.

Here is what I am doing
CWinThread *ptrDecode = AfxGetThread();
CCriticalSection c_sDecode;
static UINT mDecode(void*);
ptrDecode = NULL;

void myfuction::startThread()
{
      if (ptrDecode == NULL) {
	  ptrDecode = AfxBeginThread(mDecode, this);
	  WaitForSingleObject(ptrDecode, INFINITE);
	}
}

UINT /*WINAPI*/  mDecode(void* pParam)
{
	myfuction* pThis = (myfuction*)pParam;
	CSingleLock lock(&c_sDecode);

	lock.Lock();
	while (1) {
               if (!inputVideo.read(RTSPframe)) {
					//Error
					break;
				}
				
				if (!theApp.RTSPChangeCam) // if == false break out of while loop
					break;

				inputVideo.read(RTSPframe);
				cv::resize(RTSPframe, RTSPResize, cv::Size(RTSPWidth, RTSPHeight), 0, 0, INTER_LINEAR);
				theApp.DX11Images->render();
        }
ptrDecode = NULL;
	theApp.KillDecoder = false;
	lock.Unlock();
	return 0;
}

void myfuction::OnDestroy()
{
	CDialogEx::OnDestroy();
	
	//## make sure nothing is being rendered ##//
	//## kill any RTSP Streams ##//
	theApp.RTSPChangeCam = false;
	while (ptrDecode != NULL) {} // wait until thread exits

}

Open in new window


In OnDestroy() function the while loop waits until ptrDecode == null after theApp.RTSPChangeCam is set to false this cause the while loop in the thread to break and set ptrDecode to null and the dialog then can safely exit this work fine in debug mode and my watch window is showing me that ptrDecode has been set to null but in Release mode ptrDecode dose gets set to null if I place a break point in the thread code but then is reset to not null (seems to get reloaded) when my bullet point hits ptrDecode in the OnDestroy() function, I do not know why this is being re initilized after its been set to null. At no point in my code dose the thread get called again and it only dose it in Release mode.
Is there a setting in my release properties I need to change any help would be great
Regards
Nigel
0
Code returning error message.  Unsure how to fix.

exit status 1
main.cpp:19:1: error: expected unqualified-id before '{' token
 {


Here's the code:

#include <iostream>
#include <iomanip>
using namespace std;
const int arrsize = 9;
int main()
{
int i = 0;
int j = 0;
int matrix[3][3];
cout<<" please enter 9 digits "<<endl;
for (int i = 0; i < 3; i++)
{
  for (int j = 0; j < 3; j++)
  {
    cin>>matrix[i][j];
  }
}
}
{
for (int i = 0; i < 3; i++)
{
  for (int j = 0; j < 3; j++)
  {
    cout>>matrix[i][j];
  }
  cout<<endl;
}
}
0
c++ Python program with Minizinc

In this project, you will design and implement a resource management module for an Operating System Simulator ‘oss’. In this project, you will use the deadlock avoidance to manage resources, with processes being blocked on their requests until those requests are safe.
There is no scheduling in this project, but you will be using shared memory so be cognizant of possible race conditions.

Please see the attached files customer has given me piece of codes and SOP document if someone can help me to understand whats the expectation of customer and how to met that expectation i will be very thankful.
1
Is it possible to create a cross-platform desktop application in Visual Studio 2017 that will run in both Windows 10 and Linux environments (how is it done)?  
I don't see any "New Project" options that stand out, nor much information on the web.

Thanks
1
I have this bit of C Code for a project I working on for a project.  
logit("Username: %s Password: %s", authctxt->user, password);

Open in new window

This is going to be used in a proof of concept project and I want to obscure the real password.  I was thinking of either replacing the whole password with a set of characters or maybe keeping the first and last two characters and replacing the rest with a set of characters.  Maybe Xs.   Looking for suggested modification.
0
I want to retrieve File Description from an exe in Windows. what a structure i need to pass to paremeter 3 of verqueryvalue? when i try to compile i get stFileDescription is undefined.

DWORD dwLen;

VS_FIXEDFILEINFO    *pFileInfo;

UINT                pLenFileInfo;

dwLen = GetFileVersionInfoSize("D:/firefox.exe", NULL); 

BYTE *test = new BYTE[dwLen];

GetFileVersionInfo("D:/firefox.exe", NULL, dwLen, test);

VerQueryValue(test, "\\StringFileInfo\\%04x%09x\\FileDescription", (LPVOID*)&stFileDescription, &pLenFileInfo);

delete[] test;

cout << stFileDescription;

Open in new window

0
I have  a MFC console application created using Visual Studio 2017,
Log.h file
class CLog
{
public:

	CLog();

	static	void Log(LPCTSTR str, BOOL bError = FALSE); 
	static	void Log(LPCTSTR str, BOOL bError, LPCTSTR szFileName);
	static void SetPathName(CString& strName);
	
private:
	static CString m_strLogPathName;
};

Open in new window


Log.cpp
#include <afxwin.h>
#include "Log.h"

using namespace std;

CLog::CLog()
{
	
}

void CLog::Log(LPCTSTR szMsg, BOOL bError)
{
}

void CLog::Log(LPCTSTR szMsg, BOOL bError, LPCTSTR szFileName)
{
}
void CLog::SetPathName(CString& strName)
{
	CLog::m_strLogPathName = strName;
}

Open in new window


The above code is giving the compilation error:

Error      LNK2001      unresolved external symbol "public: static class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > CLog::m_strLogPathName" (?m_strLogPathName@CLog@@2V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@A)      TestH1      D:\Test\TestH1\TestH1\Log.obj      1      
Error      LNK1120      1 unresolved externals      TestH1      D:\Test\TestH1\Debug\TestH1.exe      1

Thanks for your help
0
Hi I have a 2D vector in a library which gets populated with different types of data this part is working fine now I need to pass the 2D vector back to my main app from a function call but this function call is failing

Here is the structure that makes up the vector in the library and how I am trying to call the data in the vector from a function:
//Library code
typedef struct _DEVICEDETAILS
{
	std::string IPaddr;
	int HTTPPort;
	int HTTPSPort;
	int RTPSPort;
	std::string Model;
	std::string Name;
	std::string token;
	std::vector<std::string> RSTPURL;
	std::vector<char*> data;
	std::vector<size_t> datalen;
	std::string _mediaXaddr;
	int Encoding;
	int Width;
	int Height;
	int Quality;
	int FrameRateLimit;
	int EncodingInterval;
	int Bitrate;

}DEVICEDETAILS;

struct ONVIFDEVICE
{
	std::string MacAddr;
	std::vector<DEVICEDETAILS> _videotype;
};

ONVIFDEVICE m_MacAddr;
std::vector<std::vector<ONVIFDEVICE>> v_Device;

void GetOvifInfo(std::vector<std::vector<ONVIFDEVICE>> &returnInfo)
{
  other code .......
   int m_size =v_Device.size();
   v_Device.resize(m_size+1);
   v_Device[nFindDev].push_back(m_Mac); // info gets populated into each element here
   nFindDev++;
   
  //Need to do a deep copy from vector v_Device to  vector returnInfo

}

// Main App code
typedef struct _mDEVICEDETAILS
{
	std::string IPaddr;
	int HTTPPort;
	int HTTPSPort;
	int RTPSPort;
	std::string Model;
	std::string Name;
	std::string token;
	std::vector<std::string> RSTPURL;
	std::vector<char*>

Open in new window

0
Introduction to Web Design
LVL 12
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

I started with asking what the different is between "mode" and "flag", see: https://www.experts-exchange.com/questions/29122213/What-is-the-difference-between-mode-and-flag.html

However, I see that people are using different definitions for a flag. So it's better to start with the question: what is the definition of a flag? I'm not asking for general definitions, or your own definition, but specifically use the definitions in this post (and if necessary correct them and tell me what's wrong about the existing definition).

See: https://techterms.com/definition/flag

In computer science, a flag is a value that acts as a signal for a function or process. The value of the flag is used to determine the next step of a program. Flags are often binary flags, which contain a boolean value (true or false). However, not all flags are binary, meaning they can store a range of values.

Let's start with:

a flag is a value

So apparently, according to this definition, a flag IS a value. So a flag can not be seen as something that be two different values (two different states).

The next sentence confirms that:

Flags are often binary flags, which contain a boolean value (true or false).

Let's say we have c++ std::bitset, but it's about 1 bit. Firstable, it's important to be aware of the difference between:

1. setting the flag
2. setting the bitset

The bitset can be 1 or 0  (in this case because we have one …
0
When it's about "flags", I've noticed that different people have different ideas of what a flag is. Some people start to talk about "bit set" when it's about flags. I think the problem lies with the underlaying definitions. It looks like things are not well defined. So for this question, forget about your own ideas/definitions of what a bit set is, just follow the definitions in this post (and change them if necessary). Also forget about flags, this post is specifically about "bitset". First let's start with some "definitions":

See: http://www.cplusplus.com/reference/bitset/bitset/ (std::bitset)

A bitset stores bits (elements with only two possible values: 0 or 1, true or false, ...).

And see: http://www.cplusplus.com/reference/bitset/bitset/set/ (std::bitset::set)

all bits (1)      
bitset& set();
single bit (2)      
bitset& set (size_t pos, bool val = true);

(1) all bits
Sets (to one) all bits in the bitset.
(2) single bit
Sets val as the value for the bit at position pos.

I understand this. But now first let's start at the beginning and let's define a "bit". Let's define it like this:

A bit is an element of two possible binary values: either 0 or 1.

So let's see a bit as a box that contains a ball or a box that doesn't contain a ball. Now let's take a look at a bitset that represents the number 4:

 -----------------------
|0     | 0     |  1     |
|0*2^0 | 0*2^1 |  1*2^2 |
 -----------------------
3 boxes: 
Box 1: no ball
Box 2: no ball
Box 3: ball

Open in new window

0
I have following version of eclipse IDE installed in my computer:
Eclipse IDE for C/C++ Developers
Version: 2018-09 (4.9.0)

I created a workspace.  There are number of Templates for New C / C++ Project.
I need to import very large 'C' source code files into my project.  I won't be compiling code in eclipse.  I'll just be navigating source code.
Which Project template should I select?  Is there a way to create project without selecting a project template?
0
I had a window on which i am drawing a bitmap , and am dragging the window basically the bitmap. My code is capturing the bitmap from one location and the problem is when i drag it the bitmap keeps changing to the bitmap to the place where my mouse is moving.  Suppose i have 2 images drawn on screen . when i start dragging from the place near to image 1 and keep on moving bitmap also changes, i am not getting it how is it changing , shouldn't bitmap should remain same ? Why is it changing if the position of my window is changing , i have checked the coordinates are same they are not changing which i have passed in BitBlit function

in Onpaint() i have used this code -
hBitmap = ::CreateCompatibleBitmap(m_panel_hdc, 600,600);
paint.BitBlt(100,100,585,600, window_dc,599,77,dwRop);
::SelectObject(m_drag_wnd_compatible_dc, hBmpOld);


OnMouseMove()
I am calling MoveWindow() API for moving the window.

And also when i try to move the window fastly with mouse the traces of bitmap of getting dragged are left behind and take time to be back in normal position.
Any help would be really appreciated.
0
Yellow rect is the window it's moved from left to rightI am implementing a draggable window and in my mousemove i am setting it's position using MoveWindow() API but problem is while it is moving it is leaving its trace behind i have attached the image The place where it was present earlier is not getting erased, i have used OnEraseBackground to true and false
0
I'm trying to set up a uncaught exception handler at process level in a
> vc++ program
> set_terminate() and set_unexpected()
> My program is multi-threaded.  I'm already able to set up my handlers in
> the main thread and catch all the exceptions thrown by the main thread.
> What I'm not able to do is to trap all the uncaught exceptions thrown by
> non-main threads.

Can you please give me sample program inside the Winmain() how to call the set_terminate() and set_unexpected()  functions and how to declare outside of the Winmain().
0
I'm trying to investigate a problem with resource files generated by Google Omaha. These resource files contain a place-holder token (%1!s!), which is substituted with branding details during the build process. There are numerous language resource files that contains string tables and this

Here is an example string: "%1!s! some arbitrary text"

Where %1!s! is a place-holder for some substitution text?

My question: is this place-holder substitution mechanism a standard part of the Windows resource file mechanism? If so, can someone please either explain how it works? Where does it get the text used to substitute the place holder? I'm assuming the place-holder works similar to place-holders in printf? If so, how does it know which text token to replace this with? If this is not a standard resource file mechanism, does anyone have a clue as to how Omaha does this during the build process?

Many thanks.

Note: I'm not looking for suggestions to use a different approach. This is how Omaha does it and I just need to understand how this works. Thank you.
0
Hey!

I am developing an application using JetBrains CLion 2018.2.4 with cmake 3.12.2 and Visual Studio 2017 compiler.
Let me set up things first.

Here is the base class:
class Header
{
public:
   enum MessageType
   {
      Message = 100,
      Command = 101,
      InvalidMessage = 102
   };

   Header();
   Header(Header::MessageType messageType);
   virtual ~Header() = default;

   Header::MessageType GetMessageType() const;
private:
   Header::MessageType m_messageType;
};

Header::Header() :
   m_messageType(Header::MessageType::InvalidMessage)
{
}

Header::Header(Header::MessageType messageType) :
   m_messageType(messageType)
{
}

Header::MessageType Header::GetMessageType() const
{
   return m_messageType;
}

Open in new window


Here is the derived class:
class Message : public Header
{
public:
   Message();
   ~Message() = default;

   void SetMessage(std::string message);
   std::string GetMessage() const&;

private:
   std::string m_message;
};

Message::Message() :
   Header(Header::MessageType::Message),
   m_message("")
{
}

void Message::SetMessage(std::string message)
{
   m_message = message;
}

std::string Message::GetMessage() const&
{
   return m_message;
}

Open in new window


Here is how I'm acessing the function GetMessage();
int main()
{
   Reader reader;

   auto basePtr = reader.ReadAll(message);
   auto derivedPtr = std::dynamic_pointer_cast<communication::Message>(basePtr);
   std::cout << "read: " << derivedPtr->GetMessageType() << ";" << derivedPtr->GetMessage();
}

Open in new window


When I try to execute GetMessage() like up above, I get the error below:

Server.cpp.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall communication::Message::GetMessageA(void)const & " (?GetMessageA@Message@communication@@QGBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
Server.exe : fatal error LNK1120: 1 unresolved externals

Open in new window


It has to do with the function GetMessage() but I'm failing to see what is wrong. If I remove that call, everything compile fine.
Also, I do the exact same call in other class and it is working fine.
Help is needed!!!
0
dup2(int oldfd, int newfd);

Open in new window


This is an equivalent of:

close(int newfd);
dup(int oldfd);

Open in new window


By closing "newfd" first, it becomes the lowest-numbered unused file descriptor (normally). Because of that the oldfd is copied to newfd (dup system call). So far, everything is clear.

Now see: http://codewiki.wikidot.com/c:system-calls:dup2


dup2 is a system call similar to dup in that it duplicates one file descriptor, making them aliases, and then deleting the old file descriptor.

Actually I don't think the old file descriptor will be deleted?

See: http://man7.org/linux/man-pages/man2/dup.2.html

After a successful return, the old and new file descriptors may be used interchangeably.

If the old file descriptor will be deleted, then they would not say something like that. Is wikidot.com just wrong about this?
0
Become a Microsoft Certified Solutions Expert
LVL 12
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

I'm trying to understand the structure of the open file table. During this search I'm reading things that look like (for me) they are in contrast with each other.

In a system there is a:

File descriptor table:
This table is located in user space and is associated with a certain process (per-process).

Open file table:
This table is located in kernel space and is associated with all processes (process-wide).

Entries in the file descriptor table point to the open file table. This all is clear. Now let's go to the structure of these tables. For example, see: https://elixir.bootlin.com/linux/v3.18/source/include/linux/fdtable.h#L24

struct fdtable {
        [...]
};

Open in new window


And:

/*
 * Open file table structure
 */
struct files_struct {
        [...]
};

Open in new window


Also this is clear. But now see for example: http://www.andrew.cmu.edu/user/gkesden/ucsd/classes/sp17/cse291-a/applications/ln/lecture5.html

Per Process File Information


struct files_struct { /* kept within task_struct (PCB) */
        [...]
};

Here they are talking about files_struct when it's about "per process file information". I don't understand this, because the open file table is process-wide. This is for example what they are saying:

The count variable tracks the number of files the process has open

But imagine ... two different processes point to the same entry in the open file table. I think …
0
Dear experts,

I am learning C++

I have some idea about Objects in C++

Is there an online course which can teach me 'objects' and ' Data Structures' in great detail?

Kindly suggest.
0
Hello,
There are 2 COM interfaces whose implementation is proprietary

I need to create a COM object (either in C++ or C# com server) and invoke it to use their functions from a c# client console application

How should i approach the task?

Thank you
0
Hi Team,
I want to design the global try/catch block inside the winmain() function and my application already do have __try and __except blocks (SEH mechanism).
So i want to add global try/catch block for that it will help us to catch the unhandle exceptions.
Please find the below code and give your suggestion where can i add the global try/catch block inside the winmain(..).

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int showCmd)
{
    MSG msg = { 0 };

    __try
    {
        HACCEL      hAccel;
        WNDCLASSEX  wcl = { 0 };
        char        errorText[1024];

        g_hInst = hInstance;

        /* register main window class */
        if (!RegisterClassEx(&wcl))
            return TPG_GenMessageDialog(NULL, "Error registering main window class.",
            APP_TITLE " Win32 Error", MB_ICONSTOP, SS_MSGDLGTIMEOUT);
        /* read ini file */
        /* create main window  code*/
        /* show window - showCmd overrides saved state if not SW_SHOWNORMAL */

        hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATORS));  /* ignore error */

        /* start it up! */
        if (!Startup(errorText, sizeof errorText))
        {
            Log(mtIgnore, SS_NOMCPMSG, TPG_LOGLEVEL_ERROR, errorText);
            return TPG_GenMessageDialog(g_hWnd, errorText, APP_TITLE " Startup Error", MB_ICONSTOP,
                SS_MSGDLGTIMEOUT);
        }
        while (GetMessage(&msg, NULL, 0, 0) > 0)
        {
1
I am considering using a Rasberry Pi as an SBC (single board computer) with Android O/S installed and programming with Embarcadero RAD Studio 10.2  (C++ builder). Is there a library or other means of using the GPIO of the Rasberry Pi and other hardware features of the SBC ?
0
I have a code in C++ which needs to be converted into VBA.

//#include <Rcpp.h>
//#include <math.h>
//#include <iostream.h>

using namespace Rcpp;
double qnormal_x,qnormal_y,qnormal_z;
double expq(double q, double w){
if(q==1.0){
return(exp(w));
}
else{
return (expl(log(1.0+(1.0-q)*w)/(1.0-q)));
}
}
double lnq(double q, double w){
if(q==1.0){
return(log(w));
}
else{
return ((exp(log(w)*(1.0-q))-1.0)/(1.0-q));
}
}
void setseed_qnormal(double v0, double z0){
qnormal_x = sqrt(1-v0*v0);
qnormal_y = v0;
qnormal_z = z0;
}
double Q8(double w, double v){
return(8*w*v*(((16.0*w*w-24.0)*w*w+10.0)*w*w-1.0));
}
double P8(double w){
return((((128.0*w*w-256.0)*w*w+160.0)*w*w-32.0)*w*w+1.0);
}
double f(double z){
return(1.0-fabs(1.0-1.99999*z));
}
void qnormal(double q){
double qq;
qnormal_y = Q8(qnormal_x,qnormal_y);
qnormal_x = P8(qnormal_x);
qq = (q+1.0)/(3.0-q);
qnormal_z = f(expq(qq,-qnormal_z*qnormal_z*0.5));
qnormal_z = sqrt(-2.0*lnq(qq,qnormal_z));
}  

// [[Rcpp::export]]
NumericVector Chaotic(int n,double q,double v0, double z0){
  double eta;
  double xi;
  NumericVector ux(n);
setseed_qnormal(v0,z0);
for(int i=0;i<n;i++){
qnormal(q);
xi = qnormal_x*qnormal_z;
eta = qnormal_y*qnormal_z;
ux[i]= xi;
}
return ux;
}

Open in new window

0

C++

57K

Solutions

24K

Contributors

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.