I want to use a dataset of type set which will have the type pair<char,string> or pair<string,string>. How can i insert values into the set, because i have to initialize the set and will not change the set during the program.
How can I define type MARKS which will be able to hold 4 elements just like array? I want to access it just like normal array elements using brackets []. In the following struct I want to use such type.
Purpose of the struct ARGUMENTS is to hold 4 pointers to string. I want to mark few positions in string so I can simple access them. E.g. name=John
Code: arguments[0][0]=0; // begin of the param name arguments[0][1]=3; // end of the param name arguments[0][2]=5; // begin of the value arguments[0][3]=8; // end of the value I mean not to save int but the pointer to the corresponding position.
"Write a declaration for a function that takes two int parameters and returns an int, and declare a vector whose elements have this function pointer type."
But it is scrappy. The visitor classes had to be placed outside the classes they belonged to, and CountB lost its template because of that. Also, it is very awkward that I have to construct a "reverse hierarchy" for the Visitor classes (which means that this has to bechanged if I ever change the hierarchy for A, B, C, ...). How to improve my solution (using acyclic visitor pattern)? Forward declaring nested classes is not possible in c++.
int main() { int a=0, c, d, N, K; bool stopBool = 0;
[Code]....
This is supposed to find take a number N and K and find all numbers between 0 and N that equal K and cout the number of pairs that fit it but it doesn't work.
I have tried to implement a much simplified version of boost::compressed_pair.What follows is a partially specialized EBO_pair<T1, T2> class template, written in C++11.The first type T1 is constrained to not be empty.The second type T2 may or may not be empty.
Goal: To allocate some memory as a char*, read in some binary data, re-interpret it as a float* and then free the memory.
My code looks like:
void someFunction(float* &result) { char * tmp = new char[1000]; //...Fill the char buffer here... result = (float*)tmp; //Reinterpret binary data as floats
[Code] ....
Is the cast back to char* necessary on the red line (or could I have validly left it as float*)? Would it be different if I had written char * tmp = (char*)malloc(sizeof(char)*1000); on the blue line (and correspondingly used free (char*)floatData on the red line?
I have an assigment to make program which deletes from sentence all words with character count which is equal to pair number , for example - [ I like C ] and the result of this program should be [I C] because the word like contains 4 characters which is pair and it should be removed.
So I started writing my program and I am stuck at this block of code -
#include <stdio.h> #include <stdlib.h> main () { char text[100], blank[100]; int c=0,d=0,i,j; gets(text);
[Code] ....
To explain what is happening - I go through all string and search for first ' ' space symbol and check its value. If it is pair then my program prints that it is not pair[because last character before space had not pair number of characters], but the hardest part comes in when i have two not pair words , because space takes one character and now when i check if i%2 == 1 the answer is false [0] for the second word .
I have a program that stores values in a map>. I use the map as a dictionary so that I can look through my map if a perticular string already exists. If a string does exist, I want to put the position that I found it at (relative to my text file) in my vector. How do I do this? So far I've tried this:
void mapInsert(string aWordNoSpaces, int index){ // check if word exists in map already, but first we need an iterator object map<string,vector<unsigned int>>::iterator it; it = wordMap.find(aWordNoSpaces); if(it == wordMap.end()){ wordMap.insert(pair<string,vector<unsigned int>>(aWordNoSpaces,index));
[Code]...
Also, why are the zeros showing up here (i've attached a screenshot and circled them): [URL]...
I've used qsort to extract the unique student IDs by jumping every four because there's 80 rows of data and twenty students.
I want to make sure it's all working and there's something very strange going on. If you look at my code, when it comes to initialising the structure with the unique student IDs it will happily print them after each one has been initialised inside the for loop (which suggests to me it's obviously done it) but, however, when I want to print them again outside the for loop in another for loop as a "double-check" it goes horribly wrong, presumably they're not in there at all? If you traverse the code to the bottom you'll see my comments.
Now in my for loop, j is going to be incremented 20 times which will correspond to the #define STUDENTS 20. So imagine the array of structure db[j] , the first loop will set i and j both to zero, retrieve the first unique ID and store it in the structure. Then i is incremented by four to acces the next unique ID and then j is incremented by 1 to insert this new ID in the structure.
I have a pointer to a C string that contains multiple lines of text. I need to change a few characters in the string (possibly adding 1-2 extra). At the moment my code looks like this (char **objectData is the pointer):
Code: char temp[350]; char* end = strstr (*objectData, "word_before_data_changes"); strncpy (temp, *objectData, 39); // Copying the first 39 symbols strncat (temp, "6-11", 4); // inputting some data strncat (temp, end, 100); // copying the last symbols.
I don't know how many there would be. Tried sizeof(end), but this cropped off last two lines for some reason. So using 100 at the moment. This sort of works, but I think it also adds some new lines or null-terminating characters in the end or something like that, because data parser cannot parse the modified data after that.
I have a problem with entering math functions in my Bisection method algorithm program. I just don't know how can I make the function that I enter in my GUI app to go from the GUI to the loop and find the root.As far as I googled I only find codes that you need to pre-enter a function in the double/float.
For example:I have a function f(x) = x^3 - cos(x) - x - 3; and I want to enter that function trough the GUI i made in c++..So this is the main code.
#include<iostream> #include<vector> #include<map> using namespace std; class foo { struct type { int i; string s; }y;
[Code] ....
In the sample code
1) why can't we use union if its members have constructors 2) I am not able to insert in Map. 3) also I am not able to use object of struct type y to assign value of its members and later push_back in vector I am getting following error
knils@knils-HP:scott_mayers$ g++ vector_of_struct.cpp vector_of_struct.cpp: In member function ‘void foo::fun() const’:
Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.
I'm stuck on how to put the prime numbers into an array.
The input file has the numbers 1 & 100.
Here's what I have so far.
#include <iostream> #include <fstream> using namespace std; int main() { ifstream fin; fin.open("numbers.txt");
For some reason, my input seems to lag one behind when inserting data. Attached, I have code that I wrote along with the example of the lag. What may be wrong with my code that is causing this to lag?
I have the structure defined in the code below and need to insert a new string into the middle of the string array. I know there is a way to insert a new element with a vector. How to do this. I have tried several variations similar to uniqueList.word.insert(400,"disisdabomb"); but with no luck.
const int maxWordCount=1500; struct wordCountList { string word[maxWordCount]; int count[maxWordCount]; }; wordCountList uniqueList;
I want to insert an element into binary tree using pointer passing through functions. In my program i have used three structure which are follows :-
Code:
struct tree{ int data1; struct tree *leftptr; struct tree *rightptr; }; struct list{ struct tree **data; struct list *node;
[Code]...
Here i think problem is in allocating memory to n2 . why i do this because i want to store the address of address of left and right pointers of tree and extract that address to get the address of left and right pointers. Is my method correct ?
Below is an extracted portion of an example exercise from the C Programming Language book:
Code: void escape(char * s, char * t) { int i, j; i = j = 0;
while ( t[i] ) { switch( t[i] ) {
[Code] ....
Here's my problem with this. s is a pointer to a char array. That means each index stores 1 byte. A backslash character '' is one byte. In above example, we escape it with a second backslash character: ''. That means we have two bytes there. So why does it allow inserting two bytes into a one byte index?