c++

C++ String Testing string

Read a string from the user into a string named string1. Test it with the data: Good morning. Print the following heading and the data contained in string1: Exercise 1 Good morning Give me a hint to write this code. Thank you Source: c++

Compilation of OpenCV using CMakeList under ROS

I am trying to compile openCV code using CmakeList.txt (under ROS), my CmakeList is working, because on another PC it is working well. I installed OpenCV and in openCV examples directory I compiled examples using g++ and some flags, compilation was successful. But when I want to compile my other code using CmakeList, I get this error: CMakeFiles/aupark_node.dir/src/wrapper.cpp.o: In function…
Read more

SSL_accept returns SSL_ERROR_SSL

I have a strange error working with openssl in c++ with non blocking sockets. SSL_accept return SSL_ERROR_SSL. error string is “error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol” as obtained from ERR_error_string(ERR_get_error(), NULL); ssldump: New TCP connection #1: localhost(35677) <-> localhost(8084) 1 1 1443513828.4788 (0.0001) C>SV3.1(153) Handshake ClientHello Version 3.3 random[32]= e9 fc d9 2b 25 20 77 9f 5f a4 b1 eb 5d 50…
Read more

Is __finally supposed to run after EXCEPTION_CONTINUE_SEARCH?

In the following code, the function foo calls itself recursively once. The inner call causes an access violation to be raised. The outer call catches the exception. #include <windows.h> #include <stdio.h> void foo(int cont) { __try { __try { __try { if (!cont) *(int *)0 = 0; foo(cont – 1); } __finally { printf(“inner finally %dn”, cont); } } __except…
Read more

how to pass arbitrary array of structs to a function?

I am trying to pass arbitrary array of structs to a function. It compiles well but it prints nothing. Here is the arbitrary array of structs: aFriend *p_array=new aFriend[index]; The function call updateTalk(p_array, index); and the function void updateTalk(aFriend an_array[], int a_size) Also here is the whole code: #include <iostream> using namespace std; struct aFriend { string name; int days_ago=0;…
Read more

create vector made of indexes of specific values of another vector cpp

I have the following vector: int A[]={1,2,1,-2,0,0,-1,0,1,-1,-2,2} I would like to produce vectors that contains the indexes of the values of A B={4,5,7}; // A[i]==0 , i=0…11 C={0,3,9}; // A[i]==1 , i=0…11 // etc …. I’m trying to use the <algorithm> library with the commands find and find_if. ( I can create a function and make a loop in it,…
Read more

Storing and Returning Lua Userdata

I have the following classes in C++ class B; class A { B* GetB(); void SetB(B*& b) { _b = b;}; private: B* _b; } And part of the lua binding code: int A::setB(lua_State* L) { A* a = checkA(L,1) // Macro for luaL_checkudata B* b = checkB(L,2) // again similar macro a->SetB(b); return 0; } int A::getB(lua_State* L) {…
Read more

What’s wrong with this code that I wrote for Armstrong Number finder?

What’s wrong with this code that I wrote for Armstrong Number finder, it’s not giving the desired output? I’m unable to understand, if the fault is in the logic of the code, or in the C compiler I’m using. Please someone help me out. ‪#‎include‬<conio.h> #include<math.h> int main() { int n,d=0,x=0,y,z,s=0,a; printf(“Enter a number”); scanf(“%d”,&n); y=a=n; while(n!=0) { ++x; n=n/10;…
Read more