c++

C++ char* in methods

Listen people, i want to write a method that gets a line from the user, so i wrote this: static char* getline(){ char temp[0]; cin >> temp; return temp; } I also have a writeline method: static void writeline(char* text){ cout<<text<<endl; } and then i go to the main and wr...

Can you run C# Code from c++?

Can you run C# code from c++? and How? ...

How to run c++ code from c++?

If I have some c++ code as a string quantity (data) in a c++ program, can I execute the contents of that string? As using the CodeDOM in C# or the eval function present in perl, python, etc.. ...

Print an ASCII art diamond

This is a homework question I got for my programming course at school, and I'm kind of lost, so please help. Here is the question: Write an application program that prints a diamond of asterisks (*) on the screen. The number of lines in the diamond is given by the user. As an example, if the user requested a diamond with ...

STL Priority Queue on custom class

I'm having a lot of trouble getting my priority queue to recognize which parameter it should sort by. I've overloaded the less than operator in my custom class but it doesn't seem to use it. Here's the relevant code: Node.h class Node { public: Node(...); ~Node(); bool operator<(Node &aNode); ... } Node.cpp #include "...

fread terminating mid-read at null values. Also reading in garbage past expected data.

I am reading in pieces of a binary file using a FILE object in C++. Here is the fseek and corresponding fread call: fseek(fp, startLocation, SEEK_SET); fread(data, m_sizeOfData, 1, fp); m_sizeOfData ends up being an integer greater than 400 thousand. This appears that it should read all 400 thousand+ bytes from the binary file into ...

Reading in an ascii 'maze' into a 2d array

I'm writing code to read in a 7x15 block of text in a file that will represent a 'maze'. #include <iostream> #include <fstream> #include <string> #include "board.h" int main() { char charBoard[7][15]; //the array we will use to scan the maze and modify it ifstream loadMaze("maze"); //the fstream we will use to take in a maze...

Using Maven for C/C++ projects

I'm putting Maven build around cluster of amateur, poorly written and frankly - primitive C/C++ code (meaning some C, some C++). Problem is - there's lots of it in circulation currently and cannot be easily replaced. Building it requires a lot of tribal knowledge (you have to go from cube to cube just to find out how to compile/build var...

sort function C++ segmentation fault

In this code, for vector size, n >=32767, it gives segmentation fault, but upto 32766, it runs fine. What could be the error? This is full code. #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<utility> #include<algorithm> #include<sys/time.h> using namespace std; #define MAX 100000 bool compare(pair<int,int>...

WinAPI function to start help file

when you open help in e.g. Windows Notepad (Help->Help Topics) no child process is started (such as hh.exe), which IMO means there is a WinAPI function called to do the job. I searched MSDN for a while but came up with nothing. what is this function? ...

App crash on access new Database..

My application crashes on reading / writing data from the database. I have one database on c: and I copy-pasted and rename with different name. The following process is what I have used for copy...Please guide me if you have any suggestion or solution. RFs fs; fs.Connect(); CFileMan* fileMan=CFileMan::NewL(fs); CleanupStack::PushL(fil...

C code - need to clarify the effectiveness.

Hi I have written a code based upon a requirement. (field1_6)*(field2_30)*(field3_16)*(field4_16)*(field5_1)*(field6_6)*(field7_2)*(field8_1)*..... this is one bucket(8 fields) of data. we will receive 20 buckets at a time means totally 160 fields. i need to take the values of field3,field7 & fields8 based upon predefined condition. i...

Abort Core Dumped in linux for a C++ progam that works in Visual Studio

I have a C++ project that was built and runs in Visual Studio. When I try to run it in unix, it gives me Abort (Core Dumped) I am using the g++ version 3.2.2 How do i Fix this program ? It needs to run in linux. ...

How to convert from K&R C to ANSI C?

I am trying to execute following code which is the 1988 entry of Obfuscated C Code Contest. #define _ -F<00||--F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-...

Excluding boost signal calling

There is a signal and several objects with slots. I want to implement the behavior when one object calls signal and blocks its own connection. I guess a small snippet will be more informative: typedef boost::signal<void()> TSignal; template<class TSignal> class SlotObject { public: void Connect(boost::shared_ptr<TSignal> pSignal...

What's the most commonly used XML library for C++?

I saw a few libraries through a quick Google search. What's generally the most commonly used XML implementation for C++? I'm planning on using XML as a means for program configuration. I liked XML because I'll be making use of its tree-like structure. If you think you have a more suitable solution for this, feel free to mention it. I wa...

How to hack Virtual Table ?

Hi, I wanted to know how to change the address of Test() which is in Virtual table with that of HackedVTable(), void HackedVtable() { cout << "Hacked V-Table" << endl; } class Base { public: virtual Test() { cout <<"base"; } virtual Test1() { cout << "Test 1"; } void *prt; Base(){} }; class Derived...

Is using const_cast for read-only access to a const object allowed?

In C++ I have a function that only requires read-only access to an array but is mistakenly declared as receiving a non-const pointer: size_t countZeroes( int* array, size_t count ) { size_t result = 0; for( size_t i = 0; i < count; i++ ) { if( array[i] == 0 ) { ++result; } } return result...

ASCII "graphics" library?

Is there a platform-independent C/C++ library that can draw simple "graphics" in pure ASCII in a console program? For example (VERY roughly) I could call a function in the library like rectangle(3, 6); to get the following output: ****** * * ****** Ultimately, I would love to be able to plot simple graphs based on input data tables...

Diff between Instance id and Hardware id?

What is the difference between Instance Id and Hardware id? Is this unique for any usb device? I connected one usb device (which is used as license for my application). When I connected to differenct ports it is generating different instance ids (I see in device manager details). I want to get device instance id and hardware id whene...