[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

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
OWASP Proactive Controls
LVL 12
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

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
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
OWASP: Avoiding Hacker Tricks
LVL 12
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

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
I wish I could find simple example C++ code to read a JPG file from the disk and put it in the clipboard.
Windows, MFC, VS2017.
0
Question is related to C++ STL list::sort(Compare) where Compare is now a template.

I am looking for the correct syntax to override the list::sort(Compare) definition to work with list<pair<int, T> > definition.

//-The Compare Function

template<typename W>
bool weightsort(const pair<int, W> &node1, const pair<int, W> &node2)
{
    return (node1.second <= node2.second);
}


//- Abbreviated class definition containing  STL list definition and call to sort

template<typename T>
class Graph {
    ...
    vector<T> shortest_reach(int startId, T sigWeight) {
        ...
        list<pair<int, T> >                                       frontier;   //-Nodes currently on the Queue to be Explored.
        typename list<pair<int, T> >::iterator      fit;
        ...
            frontier.sort(weightsort);
        ...
    }
    ....
};


$ c++ program.cpp

error: no matching member function for call to 'sort'
            frontier.sort(weightsort);
            ~~~~~~~~~^~~~

usr/include/c++/v1/list:1059:14: note: candidate template ignored:
      couldn't infer template argument '_Comp'
        void sort(_Comp __comp);
             ^
/usr/include/c++/v1/list:1056:10: note: candidate function not viable:
      requires 0 arguments, but 1 was provided
    void sort();
         ^
0
Dear experts,

In the recent past I have been inquiring or seeking your expert guidance on pursuing a career in Financial Engineering.
I have now reached the stage of working on objects in C++. Once I am thorough with C++ and after having worked on ‘Introduction to C++ for Financial Engineers’ by Daniel J Duffy, I plan to do a project work.
This project work will be done by me while I am in leave.
Can I request if anyone can guide me on selecting a project on Python/C++?
Which platform will be robust for this purpose?
Is there a book I can purchase and practice? Can I use the knowledge I gain by practicing this book in my interview process?

Kindly guide me.
0
could you anyone explain how we will convert c++ code to PHP ?
0
I want to create a server(OS: CentOS) which will be acting as an interface to an Android app(client) and the database.

I am not much experienced in programming and I just want a little bit of guidance right now to get started.
I have decided that I want to program the server in C++(though it's not an easy language but I believe there's much more to learn while programming in C++)

The basic functionality I want from my server:
1. It will interact with the app via https.
2. The server and client(app) will communicate via REST APIs.

I want guidance in terms of the most stable and well documented external C++ libraries that I should use to program the above server(I've looked at zmq, libcurl, netlib-cpp but due to my lack of experience I don't even know if these are really related to my problem statement). Thanks in advance. Please feel free to attach any blog/article/video which might be relevant.
0
Link to the problem:

The code works fine on my own system, but while submitting shows wrong answer?

 
   #include <stdio.h>
    void main()
    {
    	int t, n, count;
    	scanf("%d", &t);
    	while(t--)
    	{
    		count=0;
    		scanf("\n%d",&n);
    		while(n>0){
    		if(n%10==4)
    		{
    			count++;
    		}
    		n=n/10;
    	}
    	printf("\n%d", count);
    	}
    }

Open in new window

0
Become a Certified Penetration Testing Engineer
LVL 12
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

What is the issue with the above code and how would you fix it?
indentation does not matter in this code, ":=" denotes the substitution, and "=" is the equal comparator.

========
Initial state of an array "a":

[[2, NULL, 2, NULL],
 [2, NULL, 2, NULL],
 [NULL, NULL, NULL, NULL],
 [NULL, NULL, NULL, NULL]]

========
Main function:

FUNCTION foo()
    FOR y := 0 to 3
        FOR x := 0 to 3
            IF a[x+1][y] != NULL
                IF a[x+1][y] = a[x][y]
                    a[x][y] := a[x][y]*2
                    a[x+1][y] := NULL
                END IF
                IF a[x][y] = NULL
                    a[x][y] := a[x+1][y]
                    a[x+1][y] := NULL
                END IF
            END IF
        END FOR
   END FOR
END FUNCTION


What does the foo function do?

How could you make foo more generic? Can we have three possible generalization directions ?
0
I have an issue using an ADOQuery component with C++ builder.
If I execute a simple query "select * from Frames where FrameID = 1934411" the result is no record returned when Frames is a view.
However, if I copy the entire view contents into a table and then run the query against the table then the Record is found ?
The database is a Microsoft SQL Server version 12.0.5207.0

If I run the query on the view or the table using Microsoft SQL Server Management Studio then in both cases the record is returned.

Can this be fixed to use the view ?
0
Hi All

I have a query regarding  memory related issue I am getting in one of my web service.
I have made a service using c# which is calling C++ third party dll. While running the service I am getting below error.

"Memory gates checking failed because the free memory is less than 1%."

After going through in deep, i found that there is some memory leak issue exist in the dll.
do we have any way by which-

1. we can release the used memory by c++ dll in c#?
2. Within service or using IIS, can we put a check by which how much free memory, service is using we will get to know and then and there can do the forceful recycle?

any idea will help.

Thanks
0
Hi I am trying make a deep copy of the structure below which will contain the decoded video frames and copy to a new element in a vector without each previous element being overwritten.
The structure below is being populated as the memory in debug mode is increasing as expected with each pass of the while loop.
struct YUV_Buffer
 {
mfxFrameSurface1  *mSurface;
YUV_Buffer(mfxFrameSurface1 *pBuf = { 0 })
    : mSurface(new mfxFrameSurface1[sizeof(mfxFrameSurface1)])
{
    memcpy(mSurface, pBuf, sizeof(mfxFrameSurface1));
}

YUV_Buffer(const YUV_Buffer& YuvBuf) 
 : YUV_Buffer(YuvBuf.mSurface)  
{}

YUV_Buffer& operator = (YUV_Buffer YuvBuf) {

    std::swap(mSurface, YuvBuf.mSurface);
    return *this;
}

~YUV_Buffer() {
        MSDK_SAFE_DELETE_ARRAY(mSurface);
}
  };

Open in new window

I am calling the structure and copying the elements into the vector with each iteration of the while loop "mfxFrameSurface1 pVPPSurfacesOut[nSurfIdxOut]" contains all the information regarding the decoded video frame I need to copy pVPPSurfacesOut[nSurfIdxOut] to the vector mBuffer.push_back(root) using a deep copy so the data that the pointers in the structure are pointing to are also copied but what is actually happening is the last frame processed is overwriting all previous elements in the vector. Each time the loop passes like this: I have removed the code that is decoding each frame as its no relevant I just need to work out why the elements are getting overwritten in the vector
while(1){
std::vector<YUV_Buffer> mBuffer;
YUV_Buffer root(pVPPSurfacesOut[nSurfIdxOut]);
mBuffer.push_back(root);
}

Open in new window

each iteration of the while loop populates pVPPSurfacesOut[nSurfIdxOut] structures which contain pointers with video information like height width buffersize … and the video data its self in a NV12, YUV420 colour space, I need to access each frame from the vector mBuffer but when I try to access the vector mBuffer[0]… Im getting the last frame copyed to the vector.

Regards Nigel
0
Hello , i've the following routine :
int Asio_Send_Pck(int iSendt,int Lsocket,char * Lbuff,int Len)

{

    LSession* iTempLSession = reinterpret_cast<LSession*>(Lsocket);

    boost::asio::async_write(iTempLSession->socket() ,

                              boost::asio::buffer(Lbuff, Len),

                              boost::bind(&LSession::handle_write, 

                              iTempLSession,

                              boost::asio::placeholders::error,

                              iTempLSession->data,

                              iSendt

                              ));

    return 0;

};

Open in new window


But i always get an Invalid Arguments .

Here's my Lsession class :

class LSession
{
public:
  int readlen;
  int userdata;
  int deadtime;
  enum { max_length = 1024};
  char data_[max_length];
  
   LSession(boost::asio::io_service& io_service)
        : deadtime(0), socket_(io_service)
    {
        readlen = 0;
        userdata = 0;
    }

  ~LSession()
  {
	  socket_.close();
  }

  tcp::socket& socket()
  {
    return socket_;
  }

  void start()
  {	  
    socket_.async_read_some(boost::asio::buffer(data_, max_length),
        boost::bind(&LSession::handle_read, this,
          boost::asio::placeholders::error,
          boost::asio::placeholders::bytes_transferred));
  }

  void handle_read(const boost::system::error_code& error,
      size_t bytes_transferred)
  { 
    if (!error)
    {
	
	  try
	  {
	  if(Callback_readdata!= NULL)
	  

Open in new window

0
Hello, are you able to help me in creating a function which will convert an enum value to an actual image in C++?
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.