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 am not understanding basic concepts in php

I learned that from c++
& (reference) is an address in memory
$ is value of address
* is also a memory location but I do not know how it is different than &
  (is * in php?)

Where can I learn about basic memory concepts?
The c++ example used 4 bit machine code where there are 16 addresses with 16 values
Every cell has an address and a value.

Is this the lesson where I define a variable as int, string, float?
0
I want to add threads to a multi-platform C++ application.  I've been using gcc with mingw on Win 7 and want to upgrade to mingw-w64.  When I start the install of mingw-w64 it asks whether I want POSIX or Windows threads.  

Does this mean there is no "standard" thread in C++2011?

Other sites imply that POSIX thread is an emulation on Windows and raise questions about it's reliability.  Is selecting POSIX threads on Windows a viable option?

Would it be safer for now to use boost::thread and wait for C++2014 to implement really standard threading?
0
Consider

#if 1
void 
foo ( boost::optional < unsigned int > xx = boost::optional < unsigned int > () ) {
  boost::optional < unsigned int > temp ( xx ) ;
  std::cout << temp << std::endl;
  unsigned int * ptr =  reinterpret_cast < unsigned int * > ( &temp ) ;
  std::cout << *ptr << std::endl;  
}
#endif

#if 0
void 
foo ( unsigned int xx ) {
  unsigned int temp ( xx ) ;
  std::cout << temp << std::endl;
  unsigned int * ptr =  reinterpret_cast < unsigned int * > ( &temp ) ;
  std::cout << *ptr << std::endl;  
}
#endif 

// late
  foo ( 1212142 );

Open in new window


std::cout << *ptr << std::endl;   produce the wrong result with the boost::optional version.  Why and what's the solution?
0
Hello,

I have just set up wxDev-C++ on my desktop but when I try to run a simple program I get an error message stating that the system cannot find the file specified. I have posted the code below.

Thanks.

#include <iostream>
#include <iomanip>
#include <conio.h>
#include <math.h>

using namespace std;

int main()
{
int data[5];
for (int index=0;index<5;index++)
  {
  data[index]=(index+1);
cout<<"Element "<<index<<" contains "
    <<data[index]<<endl;
  }
getch();
return 0;              
}
0
I am planning to implement a shared memory in my application for IPC communication between two process.
I found this nice article which helped me understanding how to use shared memory.
http://beej.us/guide/bgipc/output/html/multipage/shm.html

I have couple of question wrt to synchronization and failover:

1. If two process are sharing shared_memory, is there a synchronization method so that only one can write to it (similar to pthread_mutex_lock/unlock or sem_wait/post). I tried googling but could not find a nice article.

2) Failover scenarios: Lets say if there is some synchronization method. I am just making an example. lets say if one process does pthread_mutex_lock on shared_memory and the process dies or exits for some reason. Will that shared memory be locked forever by the kernel?
0
I want to read a char array from a file using ifstream.  However I am getting extra garbage at the end of the read in string.  How do I eliminate that?   Please see attached files.

Thank you!
myTest.cpp
testFile.txt
stringAsReadIn.txt
0
I do not understand
design patterns gang of four
I forget what I read minutes after and can not apply.

but I do think I am learning from two oop books that do not contain much code
http://www.amazon.com/gp/product/0321861272

http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678


Are there other basic less code oop books

Please add other object oriented language zones.
0
I have been unable to use system() or Winexec() or CreateProcess to spawn a process to run another executable.  Granted the other executable was C++ with an RInside component instantiated within and compiled with gcc (of Rtools fame).

These same techniques had no trouble launching notepad.exe.

I am expecting my program to launch a fresh process and wanted to step through the parent process (the spawner) in debug, but whenever I did that, all I get is DOS virtual VM 'blinking'.  Only when I ran my executable outside of the debugger did the program run to completion.

Granted, I could run a .bat very easily and in ran without a hitch, but the nested .exe within the .bat only blinked a DOS VM and didn't run the pgm.

I cannot understand why hitting STEP would spawn a new process or make a system call in a different way inside the debugger.  If a process is spawned, why would it matter if it was spawned as a result of stepping through code.
0
Consider

    typedef std::pair<int,std::string>  pair_type ;
    typedef std::vector< std::pair<int,std::string> > errors_t;

    static errors_t getAll() {
      errors_t result;
      // FIX ME
     // std::for_each(MMap().left.begin(), MMap().left.end(),
     //               result.push_back( boost::lambda::bind ( pair_type, boost::lambda::_1 ) ) );
      return result;
    }
 
  private:
    struct code {};
    struct description {};

    typedef boost::bimap<
      boost::bimaps::tags::tagged<int, code>,
      boost::bimaps::tags::tagged<std::string, description>
    > error_map;


    static error_map& MMap() { static error_map MMap; return MMap; }

Open in new window


How do I insert the contents from bimap into the vector of pairs?  Compiler complains about non-matching functions
0
I am learning new C++11 features.  I wrote the following program using Visual Studio 2013 Professional Edition:

#include <thread>
#include <iostream>
#include <memory>

using namespace std;

class A
{
private:
      int val;
public:
      A()
            :val(3)
      {}
      A(int i)
            :val(i)
      {}
      int getVal()
      {
            return val;
      }
};

void f(unique_ptr<A> ptrA)
{
      cout << "val fro f " << ptrA->getVal() << endl;
}

int main()
{
      unique_ptr<A> ptr(new A);
      thread t(f, move(ptr));
      //t.join();

      return 0;
}
I cannot compile my program due to the following error:
Error      1      error C2280: 'std::unique_ptr<A,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function      c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional      1149      1      MoveValToThread

How to pass unique_ptr to thread?
0
I cant get the sdk sample to work, I have included the def file but all I can see is a Tree icon which cant be clicked. I want to be able to browse shapes
0
http://www.nusphere.com/products/php_debugger.htm


I want to learn c++ on windows with a debugger that works the same as php nusphere stepping through lines so I can see order of lines run

I am not just looking to stop code execution on a certain line.
0
Hi. I have a server application that creates a named pipe using the following call:
    CreateNamedPipe( "\\\\.\\pipe\\MyPipe"                           ,
                     (PIPE_ACCESS_DUPLEX | WRITE_DAC)                ,
                     (PIPE_TYPE_BYTE | PIPE_READMODE_BYTE PIPE_WAIT) ,
                     10                                              ,
                     1024                                            ,
                     1024                                            ,
                     0                                               ,
                     0                                               );

Open in new window

and a client application that does the following twice:
    WaitNamedPipe( "\\\\.\\pipe\\MyPipe" ,
                     NMPWAIT_WAIT_FOREVER );
    hOut = CreateFile( "\\\\.\\pipe\\MyPipe" ,
                       GENERIC_WRITE         ,
                       0                     ,
                       NULL                  ,
                       OPEN_EXISTING         ,
                       FILE_ATTRIBUTE_NORMAL ,
                       NULL                  );
    WriteFile(  hOut           ,
                "Hello"        ,
                5              ,
               &dwBytesWritten ,
                NULL           ) );
    CloseHandle(hOut);

Open in new window

Everything works great the first time, but the second time, the CreateFile() client call never returns.  Do you have any idea what the problem could be?  Thank you.
0
Hi all,

Is it possible to send and receive binary messages with MSMQ?
For example, I have a struct - can I send that struct and read it back?

If yes, please point me in the right direction for an example. Thank you.
0
I need to read a jpg file and convert it in a hex string in c++ 6.0 beacuse i need to create an rtf file with image but with fieldinst i can't resize the dimensions of the image.
0
It seems that the CFileDialog functionality has changed after .net 2003.

When I invoked the CFileDialog to browse in .net 2003 This line of code (see below) returned a pointer to the file browser window but in .net 2005 and .net 2012 it returns null.

How do I obtain the browser dialog window pointer in VS 2012?

Question:

 CWnd *pp = GetParent();                          


I have a class

class MyFolderBrowser : public CFileDialog

Which is derived from CFileDialog.

I construct it and invoke it from a function as follows:

 MyFolderBrowser browser(m_projectBasePath);
   if (browser.DoModal() == IDOK)
   {
      m_projectBasePath = browser.GetPath();
      OnChangeProjectName();
   }



The DoModal invokes this code:

void MyFolderBrowser::OnFolderChange()
{
    CWnd *pp = GetParent();                          
    VERIFY(pp);
    ASSERT(::IsWindow(pp->m_hWnd));

    ASSERT(pp->GetDlgItem(IDC_MC_DIR) != NULL);



In .net 2003 this call: " CWnd *pp = GetParent(); "

would return the browse dialog window pointer,. but in .net 2005 and later it returns a null.

How doi I get  the pointer to the file dialog window in .net 2012?
0
Hi Experts,

I am making a call to _wfopen_s and getting access denied.  I'm trying to open with readonly.  I know the file is already open for writing from a call to CreateFile - and CreateFile has the flag set for sharemode=FILE_SHARE_READ.  Any idea why I can't open for reading?

Thanks!
Mike
0
So I have inherited and must finish some code written by a departing developer.  In going through it I saw the code below.  The intent is fairly obvious (or at least lets assume it is how it looks), it is trying to set flags on the transition of the PressureTimerStatusBit.

It jumped out at me because it uses '&' instead of '&&'.  To me the logical operator is more appropriate here, you should never mix and match logical tests and bitwise operators, because you can get unexpected results like 6&1=FALSE.  On the other hand, maybe its okay because all operands are boolean or 1/0.

I am trying to touch as little working code as possible, so I'm torn: should I 'fix' it (replace '&' with '&&') or is [dont mix and match logical and bitwise] not a hard and fast rule?

Thanks for any thoughts.


if (oldPressureTimerStatusBit == 0 & PressureTimerStatusBit == 1)  // these are bools
{
   self.thresholdTrippedHi = 1;
   _isPressurized = true;
}

if (oldPressureTimerStatusBit == 1 & PressureTimerStatusBit == 0)
{
   self.thresholdTrippedLo = 1;
   _isPressurized = false;
}
oldPressureTimerStatusBit  = PressureTimerStatusBit ;

Open in new window

0
Hi Experts,

I have a HANDLE h to a file that is open for writing.  Is there a way to create a handle to this same file for reading (while the file is open for writing), without providing the path to the file?

Thanks,
Mike
0
I hope to write a library of video processing algorithms using C++ 2011 and have that library be used at the back-end on both Windows and Web. Mac wold also be nice, but not a deal killer.

Would I use Visual Studio for this C++ compiler? Is this a different program than C++.NET? (I have an MSDN license, so I could get my hands on any of them)

Would I configure the project to C++ 2011 in order for the compiler to enforce that target platform? What features does C++ 2011 provide?

And what about C++ libraries for video processing which are open sourced?

Thanks!
0
In the following ex:

int myClass::getBeer(void)
{
  MyBuddy& refBuddy=getABuddy(true);
  refBuddy.getMoreBeer(1,2);
  return 0;
}
when refBuddy goes out of scope will it delete the actual object referenced?  I remember something horrible once happened along these lines and want to avoid a repeat performance.
0
I have a custom dll that I created some time back for a stock analysis program that has started to give me some problems.  From the error message of this question you can gather what the problem is - what I would like is a way to troubleshoot by an error log or some type of popup message that gives me more information since it might be a data issue (the dll has work flawlessly for years).

Preface: I am using vectors because I need some sort of dynamic array since I do not know how big the array needs to be when the dll is first called.

This dll runs across 8 CPU threads through more than 3000 symbols with many, many, MANY years of data.  The dll basically gets all of the dates, highs, lows and closes for and calculates based on that information.  Below is the vector portion of the code:

//This function returns how many rows in the axis to step through
double StepDown(double *range, double *retvals, double value, int arr_size) 
{
   int i; //have to declare i outside of if statement or will generate undeclared identifier error
   if (value>=0) {
      for (i=0; (i<arr_size) && (value<=range[i]); i++);
   }
   return retvals[i];
}

//Create Y Axis of Precentage Scale
void yAxis(struct WORK &chart, float maxHigh, float minLow, float percent)
{
   float Price = 1;
   int buff = 4; //buffer top & bottom of chart
   while (Price < maxHigh + buff * maxHigh * percent) {
      Price = Price * (1 + percent); 
   }
   while (Price > minLow - buff * minLow * percent)  {
  

Open in new window

0
Hi,

Can any one give me code/link for crossword puzzle solve. it need to search and find words in all direction .
0
it free its the express version but when i go to the page on the registration it tells me that that page is no longer available any one have a spare key or can get one for me
0
I tried CSmtp, and after investing much time found out it leaks memory and behaves erratically in x64.
If you know and use an email (free) class, not just did a search on Google, please share.
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.