C++ :: Inserting Elements In A Set With Type Pair
Jan 8, 2013
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.
View 3 Replies
ADVERTISEMENT
Oct 7, 2014
here is a piece of my code:
while(T--)
{
std::vector<std::pair<int, int> > *dragon;
std::vector<std::pair<int, int> > *villager;
[Code]....
I now wish to print the elements of the vector. How do I do it?
View 2 Replies
View Related
Feb 14, 2012
is it possible to alter the Pair function to make it use 3 elements?
View 13 Replies
View Related
Jan 16, 2014
#include "stdio.h"
char t[16] = {0x8F,0x78, 0xC6, 0x12, 0xBA,0x98, 0xA2,0x16, 0x8F,0x78, 0xC6, 0x12, 0xBA, 0x98, 0xA2, 0x16} ;
char w[44];
void main(){
for(int i=0 ; i<4 ; i++){
w[i] = (t[4*i], t[4*i+1], t[4*i+2], t[4*i+3]);
printf("%0x ",w[i]);
}
}
i want to put some elements of the t array into the w array but when i do this, it prints only t[4*i+3]
i want the output to be something like this
w[0] = t[4*i], t[4*i+1], t[4*i+2], t[4*i+3] = 0x8F,0x78, 0xC6, 0x12
w[1] = 0xBA,0x98, 0xA2,0x16
and so on
View 2 Replies
View Related
Jan 18, 2015
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.
Code:
typedef struct {
MARKS ** pointers;
} ARGUMENTS
void main(){
ARGUMENTS arguments;
[Code] ......
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.
View 8 Replies
View Related
Mar 30, 2013
"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."
View 9 Replies
View Related
Jun 29, 2014
Acyclic visitor pattern used here to count the number of elements of a certain type in a container.
struct A {
struct Visitor {
virtual ~Visitor() = default;
};
virtual void accept (A::Visitor&) = 0;
[Code] ....
Give the correct:
count = 3
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++.
View 1 Replies
View Related
May 22, 2012
What is the correct syntax? I tried something like
Code:
class myclass {
multimap<int, void(*)()> mm_fn;
...
void afunction();
...
void anotherfunction(int anint){
mm_fn.insert(pair<int,void(*)()>(anint,afunction));
}
}
and the compiler does not like it.
View 14 Replies
View Related
Oct 29, 2013
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.
View 2 Replies
View Related
Apr 10, 2014
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.
#pragma once
#include <memory>
#include <type_traits>
#include <utility>
namespace dsa
}
[code]...
Edit: added non-member swap() function template.
View 10 Replies
View Related
Dec 22, 2012
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?
View 9 Replies
View Related
Nov 20, 2014
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 .
View 2 Replies
View Related
May 1, 2013
I'm writing a function that inserts a row into a matrix and deletes the last row.
But I'm having trouble. What do I need to add to this function:
View 1 Replies
View Related
Jan 30, 2013
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]...
View 5 Replies
View Related
Aug 11, 2014
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.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
[Code]....
View 3 Replies
View Related
Jun 11, 2013
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.
View 14 Replies
View Related
Feb 8, 2013
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 "bisection.h"
#include "ui_bisection.h"
#include <QFile>
#include <QString>
#include <math.h>
#include <algorithm>
bisection::bisection(QWidget *parent) :
[code]....
View 11 Replies
View Related
Apr 1, 2015
#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’:
[Code] ....
View 3 Replies
View Related
Apr 18, 2014
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");
[Code] .....
View 1 Replies
View Related
Jan 27, 2014
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?
View 7 Replies
View Related
Dec 17, 2013
I am trying to convert decimal value 1 to 32 to hex value and insert it at 4th pos of char array and send it as hex value at the serial port .
My issue is it is converting to decimal to hex value but when it sends, it treat the converted hex value as char and sends it equivalent hex value.
For example
if decimal =1 then its hex = 1.
so , writebuffer[3] =1
But when we send whole writebuffer through send function, it treat this 1 as char and sends its hex value as 31. how to send its hex value.
unsigned int i=0;
char hex[3];
unsigned char hexunsigned[3];
unsigned int dec;
do {
unsigned char writebuffer[8] ={0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
[Code] ....
The send function is
void serial::send(unsigned char data[], DWORD noOfByte) {
DWORD dwBytesWrite;
WriteFile(serialHandle, data, noOfByte, &dwBytesWrite, NULL);
}
View 2 Replies
View Related
Nov 19, 2013
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;
View 2 Replies
View Related
Mar 28, 2014
I'm trying to insert a structure into a binary file, then read it back out into a "temporary" structure and output some values.
#include <iostream>
#include <fstream>
using namespace std;
struct b_tree_node {
int num_keys; // number of keys in this node
int key_val[3]; // key values (0 to num_keys - 1)
int child[4]; // child file addresses (0 to num_keys)
[Code] ....
View 12 Replies
View Related
Feb 17, 2013
I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linked list...
Code:
typedef struct node {
char* value;
struct node* next;
} LinkedList;
void llAddAtIndex(LinkedList** ll, char* value, int index) {
[Code] .....
View 6 Replies
View Related
Sep 7, 2014
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 ?
View 2 Replies
View Related
Apr 19, 2014
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?
View 3 Replies
View Related