C++ :: How To Create Unordered Map Of Fixed Size Vectors
Sep 19, 2013
how to create an unordered map of fixed size vectors?
Code:
unordered_map<string, vector<int>> x;
x["mumb 5"][7] = 65; // this does not work since my vector size is not set.
View 7 Replies
ADVERTISEMENT
Jun 9, 2013
I want to save the char[8][8] // fixed size 2 dimension array
to a vector
such as
vector<?????> temp;
is there anyway to approach this?
View 4 Replies
View Related
Sep 19, 2014
This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.
The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.
So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:
[1,1]
[1,2]
.
.
.
[10,10]
This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.
View 1 Replies
View Related
Dec 9, 2013
I have a vector of vectors declared as:
vector<vector<int>> v;
My program works fine with a small number of insertions to v. However, with a huge number of insertions my program stops working without telling me the reason... I guess that vectors might not grow after a certain size (im not sure)
1. What is the maximum size that a vector of vectors can grow?
2. I'm using Microsoft visual studio 2012, Is their anything I can do with the settings to increase the size of my vector? something beyond 1000000 rows?
View 6 Replies
View Related
Feb 9, 2014
I can't compile this code as I am at work and the computers are security protected, So i''l have to wait until i get home to test this, but I am pretty sure I am wrong. The problem is I have to create two vectors with 10 elements and input random numbers into it, then pick one of the elements of the second vector at random and append it to an element from the first vector at random. This has to be done 10 times and the I am assuming i have to print the 10 results. This is what I have:
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
vector<int> random (10);
[Code] ....
View 11 Replies
View Related
Feb 9, 2014
I'm trying to create a function that uses dynamic allocated arrays instead of vectors because I want to see how they work. Basically, this function asks the user to input how many people they are going to enter followed by their name; then, they enter how many of these people want to register for an ID followed by their phone #.
For example:
"How many customers will you like to enter? " 3 //user inputs 3
Bob Allen //user input
Ellen Michaels //user input
Jane Andrews //user input
[Code].....
View 1 Replies
View Related
Jan 2, 2013
I am trying to create an array with the size of the first value of one file wich is the same of the first line because the first line only have one value. Here is how i am trying to do it ...
FILE * fich;
int test;
fich=fopen(nome_ficheiro,"r");
fscanf_s(fich,"%d",&test);
int np=test;
No*aux=primeiro;
[Code] .....
View 3 Replies
View Related
Aug 27, 2013
I'm trying to make an unordered_map with a key of std::string and a data type of my own class, "Variable". This is my code that I've done:
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
class Variable { // The class that I want to have as data type
public:
Variable(double value) : _value(value) {}
[Code] .....
This code works just fine when I use double instead of "Variable", but the moment I put in the class "Variable" instead it gives my this massive error:
(cut for clarity)main.cpp|25|error: conversion from 'std::_Hashtable<std::basic_string<char>, std::pair<const std::basic_string<char>, Variable>, std::allocator<std::pair<const std::basic_string<char>, Variable> >, std::_Select1st<std::pair<const std::basic_string<char>, Variable> >, std::equal_to<std::basic_string<char> >, std::hash<std::basic_string<char> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, true, false, true>::_Insert_Return_Type {aka std::pair<std::__detail|
View 4 Replies
View Related
May 29, 2013
I have to create array with size that returns from method
int val=test();
int arr[val];
int test()
{
// Some logic and getting result as 5
return 5;
}
I would like to create arr with 5. how can i do this.
View 7 Replies
View Related
Jun 17, 2013
typedef tr1::unordered_map <string, pin *> pin_cmp;
pin_cmp _pin_cmp;
_Pins[_num_pins] = new pin (pin_id, _num_pins, s, n, d);
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
What actually the code doing?
_pin_cmp[_Pins[_num_pins]->get_name ()] = _Pins[_num_pins]; //performance profiling
I am not familiar with unordered_map which still can use with array[].I am confuse unordered_map just need key and value why will have array[]?
View 1 Replies
View Related
Jul 31, 2014
An ImageList_Create() function (see here) takes 2 parameters: cx and cy which are the width and height of each image.
Everything is good if I know in advance what size my images will have. But what if I don't?
Let's say I select 32x32 and my images are sized as 16x16. What will happen with the image list? Or my images are 48x48 and the image list should grow to accomodate the extra space. Since on Windows image list is just one big bitmap, will the height of the image list shrink/grow to 16/48 or not? Is there a way to test such behavior?
The problem I'm having is to check whether the actual images will be truncated when they are bigger that the image list initial size or not or whether I will see some extra space if the images are smaller.
The closest way I see is this function, but I am not sure its the right one to apply to the image list itself and not to the image inside the list.
How to test this properly and reliably on Windows XP+?
View 3 Replies
View Related
Jan 2, 2015
I am trying to solve some random puzzles so I do not lose/forget c++. I never used hashtables in C++ and decided I needed to brush up. I am having in creating a hashmap that holds objects with a string as a key:
Code:
#pragma once
#include <iostream>
#include <unordered_map>
class WordCount
[Code] .....
View 13 Replies
View Related
Apr 18, 2014
Working on an assignment and I've hit TWO stumbling blocks. I now have to take the first line from a .txt file and use that number to determine the size of rows to create in my program. I am using fscanf but the program hangs. How can I read in this number, store it and use it in a for loop?
The second issue is after reading this number I have to print each number in the .txt file under a different column. (Note that it skips a line after reading the row count.) The .txt file is set up as follows:
9 1 3 6 4 7 8 8 6 1
The output should look sort of like:
Number 1 3 6 4 7 8 8 6 1
Here's my attempt:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
typedef struct{
int number;
[Code] .......
View 2 Replies
View Related
Nov 28, 2014
I am trying to make a basic app that will loop through an unordered list with repeats and count how many times a specific item repeats. Example would be I select a state from the list box and it will tell me how many times it is listed.
This is the code I have up so far, trying to keep it basic. I am missing something, something related to the counter? I think I have some of the better half up but I am not sure...
Code:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstBox.SelectedIndexChanged
Dim wins As String = lstBox.SelectedIndex
Dim foundwins As Boolean = False
Dim i As Integer = -1
[Code] ....
View 2 Replies
View Related
Mar 19, 2014
I create a list of vectors (a vector of n vectors of m elements).
std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));
How I assign values? I try below, but not worked
void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}
View 1 Replies
View Related
May 14, 2013
I am reading about positive and negative infinity in c++ and i am trying to implement them in a fixed point math arthimethic implementation
I can see that max of a int will be equal to std::numeric_limits<int>::max();
and min value of the int will be equal to std::numeric_limits<int>::min();
in c++
Here as i am defining the int max and int min manually in my fixed point math implementation, my doubt is
int min = -int max; or int min = -int max -1; ?
View 1 Replies
View Related
Oct 9, 2013
I have been writing a fixed point library the would handle fixed point numbers with an 8:24 whole/fraction ratio. This has been working quite well but since I have a 24 bit fractional part, it should be able to store 2^(-24).
Code:
long long fraction_part = 0;
long long divisor = 1;
while(*string) {
fraction_part *= 10;
fraction_part += *string - '0';
divisor *= 10;
string++;
}
fraction_part <<= 24;
fraction_part /= divisor;
The issue here is that since the smallest possible fraction is 2^(-24) the divisor could end up needing more than 64 bits and so won't work. I'm not quite sure how else I could do this.
View 7 Replies
View Related
May 28, 2013
The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.
it said 1 to 255 characters
i have to use getline(cin,str);
i tried str[255] but some error happen
View 2 Replies
View Related
Feb 17, 2015
I am interested in creating a file of a given size and then randomly accessing the file to populate it. Is there a way to quickly create, for instance, a 4 GByte file in C++, initially populated with garbage?
View 4 Replies
View Related
Aug 22, 2013
the program has to accept a keypress. It should wait for some fixed amount of time. If a key is pressed within this time, the program should call a function. If a key is not pressed in this time limit the program should continue its normal execution. The problem with getch() is that it essentially requires you to press a key and it does not allow other instructions to execute until the key is pressed.
View 3 Replies
View Related
Feb 3, 2014
While testing some simple examples with glDrawArrays I noticed switching it to shaders can cut my frame rate by over half (from 600- 300). I know I am using a bunch of deprecated code in GLSL right now but I don't expect it to cause that much of an fps drop. I would say it was just my intel graphics chip but if the FFP can handle it I see no reason shaders can't.
--Windows 7 Premum 64-bit
--Intel Core i3 540
--Intel HD Graphics
//Sending 10,000 quads with GLfloats (So Vertices vector has 80,000 elements, currently no indexing).
//Vertices allocated earlier in code, before main game loop
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableClientState(GL_VERTEX_ARRAY );
glVertexPointer(2, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, Vertices.size() / 2);
[Code] .....
The highest Opengl version I can run is 2.1 so 120 in shaders. I know this is a fairly pointless test right now but it is still surprising to see, anything obvious I am missing?
View 19 Replies
View Related
Oct 31, 2014
I am working on a computer program where I need to generate points on a circle. I am familiar with this kind of algorithm:
for(d=0; d<=2*pi; d+=0.01)
{
x = cos(d)*radius;
y = sin(d)*radius;
}
However, due to the specifics of the program I am writing, I need to iterate through a fixed number of points one at a time, like so:
for ( int x = 0; x < blockSize; x++ )
{
y = ???
}
This essentially "fixes" one axis of the circle, since I can't do: x=rx+sin(d)*r.
I have tried simply: "y = sin(d)*radius;" and I get a curved shape, but it's not a circle.
My question then is, how do I get the value of y in this situation, where the x axis is incrementing by 1 through a range of values? Is it mathematically possible?
View 6 Replies
View Related
Apr 28, 2014
I'm working on a Dijkstra's algorithm with a fixed graph. My question is, how should I go about assign distance values to the graph. The user can start from any node.
View 4 Replies
View Related
Jun 19, 2014
I've come across an interesting question involving a fixed-point arithmetic class.
Suppose I've got a template that implements a fixed-point quantity. It has two characteristics: width and number of fraction bits:
Code:
template <typename RAWTYPE, unsigned int FRACBITS>
class Fixed
{
....
};
So if I want a 32-bit value with 12 bits of fraction I can declare:
Code:
Fixed<int32_t, 12> x;
Suppose I've implemented a freestanding operator+() for fixed values, and I want to be able to add different types together:
Code:
template <typename RAWTYPE1, unsigned int FRACBITS1, typename RAWTYPE2, unsigned int FRACBITS2>
???? operator+(Fixed<RAWTYPE1, FRACBITS1> lhs, Fixed<RAWTYPE2, FRACBITS2> rhs)
{
???
}
What is the result type? Obviously, it's up to me to decide this. As reference, consider the type promotion rules for native types:
Code:
short a;
int b;
int result = a + b; In this case, the short value is promoted to the int value, and the addition happens on int.
It would seem a similar rule (go to the wider type) would be appropriate for fixed point. But there is another dimension to the problem, which is the number of fraction bits. Should you go to the wider type? Or the most precise type? Should you endeavor to minimize the number of bits which are discarded? What's the most intuitive rule?
View 10 Replies
View Related
Apr 19, 2014
all i want to do is to read a fixed char array sized 4 from user and pass it to Binary File then Print Encrypted content from the the File to the console screen .. but it seems it prints the same input every time .. and i tried everything .. it works fine with integers and strings .. but when it come to char array nothing ..
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
[Code].....
View 6 Replies
View Related
Apr 25, 2013
I am doing fixed point implementation in c++ which is done by the following code
#ifndef __fixed_point_header_h__
#define __fixed_point_header_h__
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/operators.hpp>
#include <limits>
[Code] ....
I am getting the error ambiguous overload for âoperator<â in âbeta < ((-5.0e-1) * pi)â
I know the problem the static member function cannot access the members and objects of structs. am i right?
and how to solve this problem, do i need to implement the cossin_cordic function as a non member function.
View 14 Replies
View Related