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 supporting a client who has an old system that is written in a early version of Borland C++ (BCB5) which has been installed on a Windows 7 PC and is working without any issues.
There is a need to update the hardware with a new Windows 10 PC and I have been trying to move the compiler and associated components to the new hardware with Windows 10.
I have succeeded in installing the compiler from the original CD ROM and it is functional as far as I can tell except for the fact that I have been unable to successfully install the Indy 9 Internet components.
The installation batch file "FullC5" runs and produces the required library file dclIndy50.bpl but when I try to install the package using the IDE, an error message indicates a failure due to the module not being found. I am stuck at the moment, any comments would be appreciated.

Thanks,  Roger
0
If you had to consider all the myriad of stock trading indicators out there that many novice and advanced traders alike base their trading on, and you had to group that huge number of indicators into the broadest possible major categories, what would those categories be?

I'm thinking there may only be two (2) categories off the top of my head:  Price and Volume.

What do you think?
0
I wish to detect the remote client connecting to an Indy TIdTCP server component.
I have a simple application using Embarcadero C++ Builder XE 10.1Berlin and have tested it using the Windows telnet client on the same machine as the server is running.
A snippet of the Server code is shown below and the IdTCPServer1Execute function is invoked indicating a successful connection. I also receive the text transmitted by the AContext->Connection->Socket->WriteLn(send); statement.

However , I am unable to determine the host that the server is connected to as the values of both AContext->Connection->IOHandler->Destination and AContext->Connection->IOHandler->Host;  in the code shown below both have a NULL value.
The send variable is a Unicode string wose value gets set when it's needed for transmission to the connected client.

How do I determine the client IP address ?

void __fastcall TForm3::IdTCPServer1Execute(TIdContext *AContext)
{
	UnicodeString p,q;

	q = AContext->Connection->IOHandler->Destination;
	p = AContext->Connection->IOHandler->Host;
	for(;;)
	{
		if(send.Length()>0)
		{
			AContext->Connection->Socket->WriteLn(send);
			send = u"";
		}
	}
}

Open in new window

0
I have noticed a new issue with the Indy Help that is supplied with Embarcadero and  RAD Studio and C++ builder XE 10.3 and XE 10.1 Berlin respectively.
The problem is that when trying to access help on the IdTCPClient component (for example by selecting the component on a form and pressing the F1 key), a link to the supposed help topics is displayed (as per the attached screenshot "F1_Click". when the link is clicked an error message is displayed as per the attached screenshot "IdTCPClient.TIdTCPClient_click".
I have checked the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions DWORD value MaxAllowedZone and have set it to a value of 4, having previously tried values 1 and 3, but his stillproduces an error.
   Interestingly, the error only occurs with the IdTCPClient component and help on the components such as TIdTelnet , TIdTCPServer, TIdUDPClient and TIdUDPServer work just fine.
I need to find out how to catch an Indy component exception as from memory of earlier working with original Borland compilers such as BCB5 leads me to believe that catch(Exception &e) did not work and there was a different type in the catch() exception handler.

Screen shot on invoking help
Screen shot after clicking link provided
0
hi,

I did a Windows Update for the latest updates, this was completed.
However I am looking for a microsoft download for microsoft visual C++ redistributable 2017 for windows 2008 r2 64 bit
can someone provide a working linl
thanks
0
I have copied an example of a mirror image generator from Delphi.com with a view to using it in a C++ builder project.

I get the following error in the iteration of the for loop:

First chance exception at $74CBC5AF. Exception class EInvalidOperation with message 'Can only modify an image if it contains a bitmap'. Process BitmapMirror.exe (7408)

The code is as follows:

void __fastcall TForm1::Button1Click(TObject *Sender)
{   // load an image file into Image1
	// reverse the horizontal image (make a mirror image) and display in Image2
	TBitmap *bm;
	int i,j;
	TColor c;

	if(OpenDialog1->Execute())
	{
		Image1->Picture->LoadFromFile(OpenDialog1->FileName);
	}
	bm = new TBitmap();
	bm->Height = Image1->Height;
	bm->Width = Image1->Width;
	for(i=0;i< Image1->Width;i++)
	for(j=0;j<Image1->Height;j++)
		bm->Canvas->Pixels[Image1->Width-i][j] = Image1->Canvas->Pixels[i][j];  // <<<<< This line produces the run-time error
	Image2->Picture->Assign(bm);
}

Open in new window

0
I have part of a program that is much easier to write in C++, and other parts of a program that are easier to write in C#.

Is there a way to mix C# and C++ together in one Visual Studio solution?

Can I add a C++ project to a Visual Studio solution that was created for C# code? (Perhaps create a C++ *.dll file? Oh but then I'm calling unmanaged code...)
0
I have copied the source of an Embarcadero C++ Builder XE2 project to a new PC and am trying to compile the project using Embarcadero C++ builder EX10.1 Berlin.
I get a compile error as shown below. the error is detected in a file called Functional. There is no such file in the Project folder.

Error message:

[bcc32 Error] functional(135): E2093 'operator<' not implemented in type 'string' for arguments of the same type
  Full parser context
    functional(134): decision to instantiate: bool operator less<string>::()(const string &,const string &) const
    --- Resetting parser context for instantiation...
    Unit2.cpp(6): #include Unit2.h
    Unit2.h(13): #include c:\program files (x86)\embarcadero\studio\18.0\include\dinkumware\map
    map(5): #include c:\program files (x86)\embarcadero\studio\18.0\include\dinkumware\xtree
    xtree(4): #include c:\program files (x86)\embarcadero\studio\18.0\include\dinkumware\functional
    functional(7): namespace std
    functional(131): class less<_Ty>
    functional(134): parsing: bool operator less<string>::()(const string &,const string &) const

The code where the compiler breaks is :

            // TEMPLATE STRUCT less
template<class _Ty>
      struct less
            : public binary_function<_Ty, _Ty, bool>
      {      // functor for operator<
      bool operator()(const _Ty& _Left, const _Ty& _Right) const
            {      // apply operator< to operands
            return (_Left < _Right);  //<<<<<<<<<<<<< This is the line which is shown as an error
            }
      };
0
Trying out syntax for C++11 sometimes falling into rabbit holes. This program works with a lot of trial and error. But, if I uncomment either of two lines, I get errors. I would appreciate it if someone could help me interpret the errors.
#include <iostream>
#include <vector>
#include <memory>
using namespace std;

class Base_t {
public:
   virtual ~Base_t() {}
   virtual int foo(int x) const = 0;
};

class derived1_t : public Base_t {
public:
   ~derived1_t() {}
   int foo(int x) const override {
      return 1111 + x;
   }
};

class derived2_t : public Base_t {
public:
   ~derived2_t() {}
   int foo(int x) const override {
      return 2222 + x;
   }
};

using container_t = vector<shared_ptr<Base_t>>;

int main() {
   container_t cont;
   Base_t* d1 = new derived1_t();
   Base_t* d2 = new derived2_t();
//    cont.push_back(d1);
//    cont.push_back(make_shared<Base_t>(new derived2_t()));
   cont.emplace_back(d1);
   cont.emplace_back(new derived2_t());
   cont.emplace_back(new derived1_t());
   cont.emplace_back(d2);

   int ii = 0;
   for (auto elem : cont) { cout << elem->foo(++ii) << endl; }
}

Open in new window

If I uncomment out line 34: cont.push_back(d1);, then I get these errors:
1>    \emplace_back_and_make_shared.cpp(34): error C2664: 'void std::vector<std::shared_ptr<Base_t>,std::allocator<_Ty>>::push_back(_Ty &&)': cannot convert argument 1 from 'Base_t *' to 'const _Ty &'
1>            with
1>            [
1>                _Ty=std::shared_ptr<Base_t>
1>            ]
1>    \emplace_back_and_make_shared.cpp(33): note: Reason: cannot convert from 'Base_t *' to 'const _Ty'
1>            with
1>            [
1>                _Ty=std::shared_ptr<Base_t>
1>            ]
1>    \emplace_back_and_make_shared.cpp(34): note: Constructor for class 'std::shared_ptr<Base_t>' is declared 'explicit'
1>    1 Error

Open in new window

ideone gives this error:
prog.cpp:34:22: error: no matching function for call to ‘std::vector<std::shared_ptr<Base_t> >::push_back(Base_t*&)’
     cont.push_back(d1);
                      ^

Open in new window

Now, if line 34 is commented, but line 35 is uncommented, then there are 2 errors:
cont.push_back(make_shared<Base_t>(new derived2_t()));

Open in new window

0
Ref: https://www.experts-exchange.com/questions/29138856/Unable-to-Run-Program-Using-a-Pointer-to-a-Template-Method-Inside-a-Template-Class.html

I tried to extend the referenced example by trying to pass a Pointer to Member function into a template. I am doing this because I have another application that has a template function, and I would like to pass a Pointer To Member construct into it. The below program builds and runs, but the pass_PtrToMember_Into_Function function is not invoked. When I modify the call to handle a warning, I get error messages shown below.
#include <iostream>

template<typename TYPE>
class Target5
{
public:
	Target5(const TYPE &value) : value(value) {}
	TYPE value;

	template <typename T>
	int OneParam(T a)
	{
		std::cout << "\nTarget5::OneParam(" << value << "," << a << ")\n";

		typedef void (Target5<TYPE>::*MethodTypeToCall)(T);
		MethodTypeToCall toCall = &Target5<TYPE>::Private;  // Here, the compiler picks the right overload

		auto toCall2 = &Target5<TYPE>::Private<T>;  // this alternative works OK
		(this->*toCall)(a);
		(this->*toCall2)(a);

		return 1;
	}

	template <typename T1, typename T2>
	int TwoParam(T1 a, T2 b)
	{
		std::cout << "\nTarget5::TwoParam(" << value << "," << a << "," << b << ")\n";

		auto toCall2 = &Target5<TYPE>::Private<T1, T2>;
		(this->*toCall2)(a, b);

		return 2;
	}

private:
	template <typename T>
	void Private(T a)
	{
		std::cout << "Target5::Private(" << value << "," << a << ")\n";
	}
	template 

Open in new window

0
Hi all,

In C,

crypt(userpassword, etc-password) always returning NULL in other application.

In my simple test application, working fine.

 What could be the reason?  How to fix this?

Thanks,
Bvm
0
Ref: https://goodliffe.blogspot.com/2011/07/c-declaring-pointer-to-template-method.html
Seems like others don't have the issues I am encoutering with this blog, but I have been unable to build/run case 5. I added this simple main() function:
int main()
{
	PointerToNormalMemberFunction(); // target 1
	PointerToTemplateMemberFunction(); // target 2
	PointerToTemplateMemberFunctionWithTwoParameters(); // terget 3
	PointerToTemplateMemberInTemplateClass(); // target 4
//	HoldingAPointerToTemplateMemberInTemplateClass(); // target 5 ---> Had to comment this out
}

Open in new window

In the referenced link are five cases. I am having trouble with case 5. Here is the code for this last case. Can you get a simple test program to work with this case 5? Thanks!
#pragma once

#include <iostream>

template<typename TYPE>
class Target5
{
public:
	Target5(const TYPE &value) : value(value) {}
	TYPE value;

	template <typename T>
	void OneParam(T a)
	{
		std::cout << "Target5::OneParam(" << value << "," << a << ")\n";

		typedef void (Target5<E>::*MethodTypeToCall)(T);
		// Here, the compiler picks the right overload
		MethodTypeToCall toCall = &Target5<E>::Private;
		// In this case, the compiler does not let us write the following line (parse error):
		//MethodTypeToCall toCall = &Target5<E>::Private<t;;
		(this->*toCall)(a);
	}

	template <typename T1, typename T2>
	void TwoParam(T1 a, T2 b)
	{
		std::cout << "Target5::TwoParam(" << value << "," << a << "," << b << ")\n";

		typedef 

Open in new window

0
Hello

How can i pass an argument to a visual studio .exe (C++ project) from the command line i.e. cygwin?

Please note that I do not want to pass the argument via the Visual Studio GUI under debugger->Command Arguments.

So I would like something like this:
cygwin>a.exe 4

thanks
0
Problem with visual 6 C++ code converting to visual studio 2010 c++. The following is the only code that errors out. The rest of the lib converts and compiles fine if I remark out this one line of code.
      WCHAR *printable = new WCHAR[(dwBufferSize+1)*2];
      printable[0] = '\0';

      for (unsigned long i =0;i<dwBufferSize;i++)
      {
         WCHAR scratch[3];
		 wsprintf(scratch,L"%02X", pBuffer[i]);   //This is the problem code. wsprintf requires LPSTR but scratch is WCHAR
         wcscat(printable, scratch);
      }

      *pbstrEncrypted = SysAllocStringLen(printable, dwBufferSize*2);

I've looked for code on the internet to convert a variable from WCHAR to LPSTR and back again. I could make do with that.  As near as I can see the wsprintf with the format 
code %02X takes a single wide char and makes it two hex output characters and concatenates it to the printable variable. This code was written in 2000.

Bob


      delete [] printable;

Open in new window

0
Hi all,

  I do want to store  "directory path" as a  key and corresponding value as a value. The key would be 1024.

  If I take std::map, I guess it would be performance hit with huge number of entries.

  It has to maintain this ds inside kernel module. What is the best ds to implement this in C++ 11?

Thanks,
Bvm.
0
With Lilypad e-textiles do you have to pair an Arduino board (nano or uno) with it or are these programmable themselves with Arduino software.  I have multiple LilyPad Arduino Simple Snaps and would like to program them to allow a student to push a button and have led lights go off in succession.
We are attempting to make interactive maps like what you would see in a museum.  Button goes off and the lights light up an army path or the outline of a state.
0
I have implemented a string-like class, called Str, and want to add a conversion to bool type, in order to use a Str object as a condition. The Str class is quite simple and relies on the STL vector class. Everything works fine, except that now, if I try for example to do the following:

Str greeting = "Hello, " + name + "!";

Open in new window

where "name" is a Str, then I get a compilation error, saying "'operator +': 2 overloads have similar conversions, could be 'Str operator +(const Str &,const Str &)' or 'built-in C++ operator+(const char [8], int)'.

I understand the reason for the error, but I am not sure how to fix it. How can I get around this? Below I have copied a minimal working example.

#include <iterator>
#include <vector>
#include<iostream>

using namespace std;

class Str
{

private:
    std::vector<char> data;

public:
    typedef std::vector<char>::size_type size_type;
    typedef std::vector<char>::iterator iterator;
    typedef std::vector<char>::const_iterator const_iterator;

    iterator begin() { return data.begin(); }
    const_iterator begin() const { return data.begin(); }
    iterator end() { return data.end(); }
    const_iterator end() const { return data.end(); }


    // default constructor must be defined explicitly, since non-default constructors are also defined
    Str() { }
    Str(const size_type n, const char c) : data(n, c) {  }
    Str(const char* cp)
    {
        std::copy(cp, cp + std::strlen(cp), std::back_inserter(data));

Open in new window

0
I am using zlib 1.2.7 zlibstat.lib with a Visual Studio 2015 MFC application. When I include this library I get warning messages:

zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol __stdio_common_vsprintf imported
zlibstatic.lib(gzwrite.obj) : warning LNK4049: locally defined symbol __stdio_common_vsprintf imported
zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol free imported
zlibstatic.lib(gzwrite.obj) : warning LNK4049: locally defined symbol free imported
zlibstatic.lib(zutil.obj) : warning LNK4049: locally defined symbol free imported
zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol malloc imported
zlibstatic.lib(gzwrite.obj) : warning LNK4049: locally defined symbol malloc imported
zlibstatic.lib(zutil.obj) : warning LNK4049: locally defined symbol malloc imported
zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol wcstombs imported
zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol _wopen imported
zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol _lseeki64 imported
zlibstatic.lib(gzlib.obj) : warning LNK4049: locally defined symbol open imported
OLDNAMES.lib(open.obi) : warning LNK4049: locally defined symbol open imported
zlibstatic.lib(gzwrite.obj) : warning LNK4049: locally defined symbol _errno imported
zlibstatic.lib(gzwrite.obj) : warning LNK4049: locally defined symbol strerror imported
zlibstatic.lib(gzwrite.obj) : warning LNK4049: locally…
0
I am trying to customize a print dialog in a MFC app.
I want the "pages" option to be preselected.

In CMyView::OnPreparePrinting(CPrintInfo* pInfo)
I added this at the end of the function:
      pInfo->SetMinPage(10);
      pInfo->SetMaxPage(20);
      pInfo->m_pPD->m_pd.nFromPage = 10;
      pInfo->m_pPD->m_pd.nToPage = 20;
      pInfo->m_pPD->m_nFlags |= PD_PAGENUMS;
      return DoPreparePrinting(pInfo);

When the print dialog comes up, the "all" option is preselected.
0
I'm trying to run a very simple Hello World program on a Linux workstation.  The code compiles, but when I double-click on the .exe file to run it, a window pops up with the message "An Error Occurred While Loading the Archive".  

I've attached the code and Makefile below.

What am I doing wrong?

Thanks!

#include <iostream>
using namespace std;
//hello.cpp

int main()
{
  cout << 'Hello world!\n';
  return 0;
}

Open in new window



TARGET	= hello.exe
OBJECT_01	= hello.o
SOURCE_01	= hello.cpp

$(TARGET): $(OBJECT_01)
	gcc -o $(TARGET) $(OBJECT_01) -lstdc++

$(OBJECT_01): $(SOURCE_01)
	gcc -c $(SOURCE_01) -o $(OBJECT_01)

all: $(TARGET)

clean:
	-rm -f $(TARGET) 
	-rm -f $(OBJECT_01)

Open in new window

0
Hi,
I am facing an issue regarding unicode text.
In a ATL dll project I am using LDAP to get data from Active Directory. Following is the sample code.  

IDirectorySearch *pDSSearch;
ADS_SEARCH_COLUMN col;
hr = pDSSearch->SetSearchPreference(rgSearchPrefs, ARRAYSIZE(rgSearchPrefs));
hr = pDSSearch->ExecuteSearch(strFilter, pszAttr ,dwAttrNameSize, &hSearch );

if(SUCCEEDED(hr))
	{						
		switch(col.dwADsType)
		{ 
			case  ADSTYPE_DN_STRING:
			case ADSTYPE_CASE_IGNORE_STRING:
				{			
					for(size_t x=0; x<col.dwNumValues;x++)
					{
						CString name = col.pADsValues[x].CaseIgnoreString; //fails for unicode text
					}
				}
		}
	}

Open in new window


The line CString name = col.pADsValues[x].CaseIgnoreString; works fine for English text, but returns '???' for other languages. For example if the Active directory contains any user's name in Chinese or Japanese text '邮箱' then CString name shows '???' instead of the actual unicode text.
The same code works properly in another MFC Application project but fails for this ATL dll project.

Project settings are :
Configuration Type : Dynamic Library(.dll)
Use of MFC :      Use MFC in a Static Library
Use of ATL :       Static Link to ATL
Character Set :  Use Unicode Character Set

Cannot trace what I have been missing out. Please help.
0
I have multiple instances of Microsoft Visual C++. Do I need them all?

Capture.JPG
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
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

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.