C++ :: Error In A Vector

Jun 2, 2014

I am writing a c++ program which uses a vector which contains rows and columns of a table.Unfortunately I got the following error:

IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=CCellDescr *, _Alloc=std::allocator<CCellDescr *>]" matches the argument list

argument types are: (const CCellDescr)
object type is: std::vector<CCellDescr *, std::allocator<CCellDescr *>>Here`s the code:

#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<iterator>
using namespace std;

[code].....

View 1 Replies


ADVERTISEMENT

C++ :: Error With Multidimensional Vector

Jun 22, 2013

I am having trouble accessing a one-dimensional vector as a multi-dimensional one.I have a MultiArray template class, and it is accessed using the function operator. It accesses elements through the expression row * m_columns + col. The row and col are the two inputs to the operator while the m_columns is the width/number of columns in the array. There is also a version that accesses the array with one number. Its underlying representation is a one-dimensional vector.The problem is when I try to load a level:

void Map::LoadFromFile(const std::string& filename) {
std::ifstream map_file(filename);
std::cout << m_map.GetHeight() << ", " << m_map.GetWidth() << std::endl;
std::cout << m_map_dimensions.y << ", " << m_map_dimensions.x << std::endl;
if(map_file.is_open())

[code].....

View 4 Replies View Related

C/C++ :: Error While Inserting In Map Of Vector

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

C++ :: Adding Int Type Into Vector - Runtime Error

Feb 1, 2013

I am adding int type into vector called "vi" several times like this.

std::vector<int> vi;
void addFunc(int *a, int cnt) {
vi.erase(vi.begin(), vi.end());
vi.clear();
for(int i=0; i<cnt; i++)
vi.push_back(a[i]);
}

and I call the addfunc N times every sec.

And sometimes it has runtime error on vi.push_back line.

(called stack says "_CrtIsValidHeapPointer")

View 5 Replies View Related

C++ ::  List Initialized Vector Is Having Error Messages

Jan 16, 2015

vector<int> vec1 {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};

This code worked perfectly fine in Xcode earlier today, but when I got home on visual studio 2012 express it is having an error. It's saying that the local function definitions are illegal and has a red mark under the '{' only?

View 2 Replies View Related

C++ :: Writing A Vector To Specified File - Getting Semantic Error

Mar 20, 2013

I have written a function that is supposed to write a vector to a specified file. When I build the solution, I get this error:

- Semantic error. Invalid operands to binary expression.

This is the code for the function.

void file_out(vector<task>Task, string myfilename){
//writing vector to file
string file_out = myfilename;
ofstream output_file(file_out);
ostream_iterator<task> output_iterator(output_file, "
");
copy(Task.begin(), Task.end(), output_iterator);
};

View 7 Replies View Related

C++ :: Vector String Return Length Error

Jul 10, 2013

The error is unclear but suggests Its received a bad pointer from another heap. It references dbgheap.c line 1322 and assertion failure

I have two string vector functions the first is called from the main function, the second is called from the first.

Their purpose is to receive a string of text and numbers in a semi-specific format, which the main body of the code reads from a text file, and delaminates the data as to return the first variable in the string as the variable name and the second as the variable value. Along the way it filters out a lot of the unwanted whitespace and punctuation.

E.g "{ VariableNameA 123 }" would be returned as "VariableNameA" And "123"

The code works perfectly for most of the lines in the text file but fails on one particular line where the first variable is 25 characters long. Basically it works for anything 22 characters or less. There are never more than 4 elements in the vector and each element is never intended to be longer than 25 characters.

It fails trying to return from the second split function to the first split function.

Is there a limit to the size of each vector element? I'm struggling to find a way round this without having to rewrite the whole thing.

vector<string> split(const string &s, char delim) {
vector<string> elems;
split(s, delim, elems);
return elems;

[Code] ....

View 4 Replies View Related

C++ :: Incorrect Vector Output Loop Error

Nov 21, 2014

My loop is outputting data incorrectly. I have inbound web data that come in sets of 7. I am trying to in insert the 7 records into a vector and then display the vector content followed by a new line.

Code:
char buff[BUFSIZ];
FILE *fp = stdout;
char * cstr = buff;
vector<std::string> vrecords;
while(std::fgets(buff, sizeof buff, fp) != NULL){
for(int i = 0; i < 6; ++i){

[Code] ....

expected output:

Found buy!
198397652
2014-11-14 15:10:10
Buy
0.00517290
0.00100000
0.00100000
0.00000517

[Code] ....

View 14 Replies View Related

C++ :: Error Overloading Operator / Class Template Vector

Feb 7, 2013

I'm trying to implement a vector class in C + +. However when I go to actually run the main, it generates an interrupt operating system.

MAIN.cpp
#include "header.h"
int main() {
// Definisco le istanze delle classi
vettore <int> vet;
vettore <int> vet2;
vettore <int> vet3;

[code].....

View 7 Replies View Related

C++ :: Vector Subscript Out Of Range Error Whilst Debugging

Apr 21, 2014

I have the following code. however, when I debug it gives an error saying" vector subscript out of range"

Vector based mufti-dimensional arrays

Vectors are a STL container that allow you to store pretty much anything in them. When used correctly they can be very powerful containers.

They provide an added benefit that they will automatically remove the memory they use when they go out of scope. This means that objects stored within a vector do not need to be de-allocated (but pointers to objects do). You can also do some interesting things with dynamic multidimensional arrays with vectors.

For example, if you only allocate the first dimension, then use the .push_back() to add records to the 2nd dimension it's no longer a grid, but an array with a dynamically sized 2nd dimension (much like a street of buildings each with a different amount of floors).

This functionality can be achieved using pointers, but is much harder to do.

#include <iostream>
#include <vector>
#include<conio.h>
using std::vector;
using namespace std;

[code]...

View 8 Replies View Related

C/C++ :: Error In Vector Pushback - Creating Random Unwanted Numbers

Apr 12, 2014

I'm currently writing a chunk of code that will take inputs from the user and push them into a vector until 0 is entered, at which point it will break the loop and continue on with the rest of the program. This is nothing I haven't done before, but I have never encountered this error.

The code chunk looks like this:

typedef vector <int> ivec;
int main() {
ivec nums;
int input;
while (true) {
cout << "Enter a positive integer, or 0 to quit" << endl;

[Code] ....

My standard testing input has been 3 5 6 3 8 (then 0 to quit), so one would expect my sequence to be 3 5 6 3 8...but instead after the 8 I get a random number value that is usually quite large and I cannot figure out where it comes from (ex. 3 5 6 3 8 201338847).

View 9 Replies View Related

C/C++ :: Error In Circular Vector Implementation Of Sorted Priority Queue

Mar 1, 2015

There appears to be some kind of error in by removeMin() function. Inserting items seems to work just fine but attempting to remove any items gives me the error "vector subscript out of range".

Here is my SortedPQ class... Below it you will find the quicksort implementation, in case looking at it is necessary.

template <class Type>
class SortedPQ {
private:
int front;
int rear;
vector<Type> V;
public:
SortedPQ(void) : front(-1), rear(-1), V(0){}

[Code] ....

View 1 Replies View Related

C++ :: Using Vector Push Back Function To Output Contents Of Vector (similar To Array)

Feb 9, 2015

How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.

here is my code:

#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)

[Code].....

View 3 Replies View Related

C++ :: Open File And Read In Rows To String Vector And Return Vector

Jun 7, 2012

I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,

N,N'-dimethylethylenediamine.mol

This is the function that opens the file :

Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );

[Code] ....

The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.

View 9 Replies View Related

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

C++ :: Recursive Function 2 - Create Vector Of Vector Of Integers

Mar 26, 2013

Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>

How do I make a function that creates vector of vector of every different integers?

<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>

and so on...

View 2 Replies View Related

C++ :: Find Function To A Vector Of Structures Vector

Jul 5, 2013

I have asked a related question before, and it was resolved successfully. In the past, when I wanted to use std::max_element in order to find the maximum element (or even sort by using std::sort) of a vector of structures according to one of the members of the structure, all I had to do was to insert a specially designed comparison function as the third argument of the function std::max::element. But the latter comparison function naturally accepts two arguments internally.

For instance, here is a test program that successfully finds the maximum according to just one member of the structure:

Code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

[Code] ....

And the output was this, as expected:
Maximum element S.a of vector<S> vec is at: 9
[I]max element of vec.a between slot 3 and slot 6 is: 6, and its index is: 6 vec[6].a = 6
[I]max element of vec.a between slot 4 and slot 7 is: 7, and its index is: 7 vec[7].a = 7
[I]max element of vec.a between slot 5 and slot 8 is: 8, and its index is: 8 vec[8].a = 8
[I]max element of vec.a between slot 6 and slot 9 is: 9, and its index is: 9 vec[9].a = 9

However, I now need to search and find an element of vector<myStruct> according to just one member of myStruct, instead of finding the maximum or sorting as before. This presents a problem because the function std::find does not accept such a comparison function as its third argument.

This was the description of the std::find function that I found: find - C++ Reference

Code:
template <class InputIterator, class T> InputIterator find (InputIterator first, InputIterator last, const T& val);

I could also find another function called std::find_if, but this only accepts a unary predicate like this: find_if - C++ Reference

Code:
template <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);

And once again this is either inadequate of I don't see how to use it directly, because for the third argument I would like to insert a function that takes two arguments with a syntax like this:

Code:
int x=7;
std::vector<S>::iterator result;
result = std::find(vec.begin(), vec.end(), []( const (int x, const S & S_1) { return ( x == S_1.a ) ; } ) ;

Is there another std function that I can use to make search and find an element according to just one member of myStruct?

Or perhaps there is a clever way to pass two arguments to the unary predicate.

View 4 Replies View Related

C/C++ :: Cannot Print Vector Of Vector Of Doubles

Mar 31, 2014

I am trying to print a matrix solution that I've stored in a vector of doubles. The original matrix was stored in a vector of vector of doubles. I want to print to the screen and an output file. Right now it just prints to screen column-style and the output file is horizontal-style. I tried to change the solution from vector of doubles to a vector of vector of doubles like the original matrix but when I run my code it crashes. Here is what I am referring to:

void readMatrix(vector<vector<double>> &matrix, vector<double> &b, int &N, string input) {
ifstream in(input);
in >> N;
matrix.resize(N);
b.resize(N);

[Code] ....

However when I change my printResult function to this (I removed the string argument because I just want to get it working to the screen first):

void printResult(vector<vector<double>> &sol, const int N) {
//ofstream out(output);
//int j;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++){

[Code] ....

The program crashes. Am I even printing the matrix correctly?

View 4 Replies View Related

C/C++ :: Swapping Vector Int And Vector Strings

Mar 30, 2013

I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>  
using namespace std;  
    struct InventoryItem

[Code] ....

View 4 Replies View Related

C++ :: Can't Read In Matrix Into Vector Of Vector Of Int

Mar 24, 2012

Code:
#include <iostream>
#include <istream>
#include <fstream>
#include <vector>

[Code]....

Why is it reading in nothing for the arrays, and also making the size of the total thing the total number of numbers? It should have a size of 2, not 5.

View 14 Replies View Related

C++ :: Copy Part Of Vector 1 To Vector 2

Jun 21, 2012

I am trying to copy vector to vector as follow:

Code:

std::vector<unsigned char> vec1;
//insert some values into vec1
std::vector<unsigned char> vec2;

Now I want to to copy 2 bytes from vec1 starting at index 5., why do i need to know how many bytes from the end of vec1?? can't i just specify how many bytes i want to copy from starting index?

std::copy(vec1.begin()+5, vec1.end()-??, vec2.begin());

View 2 Replies View Related

C/C++ :: Getting Header Error C2447 / Can't Find Error Source

Sep 8, 2014

Cannot manage to find the error source when i try running the program, the first part of the program runs just fine its when i try to get the temperature one that i get the error

#include <iostream>
#define pi 3.141592
using namespace std;
int main() {
double r, h; //declare variables for radious and height
double Surfacearea;

[code]....

View 1 Replies View Related

C++ :: Error C2061 / Syntax Error - Identifier (string)

Apr 3, 2013

I've just recently started to learn C++, and I'm encountering some errors I can't seem to figure out.

InventoryItem.h:

Code:
#pragma once
class InventoryItem {
public:
InventoryItem(string name, int amount);
~InventoryItem(void);
string getName(void);
int getAmount(void);

[code].....

Errors:

Code:
1>d:c++consoleapplicationconsoleapplicationinventoryitem.h(6): error C2061: syntax error : identifier 'string'
1>d:c++consoleapplicationconsoleapplicationinventoryitem.h(8): error C2146: syntax error : missing ';' before identifier 'getName'

[Code] .....

View 14 Replies View Related

C++ :: Converting 1D Vector Into 2D Vector

Apr 20, 2013

Code:
#include <iostream>
#include <vector>
int main() {
std::vector<std::vector<double> > DV; //2d vector
std::vector<double>temp(8,0.0); //1d vector

[Code] .....

The conversion actually works but it does not give the expected the result. The output should be:

Code:
1 2 3
4 5 6
7 8

and it outputs:

Code:
123123123

View 5 Replies View Related

C++ :: What Is Another Name For A Vector Inside Of A Vector

Sep 11, 2013

What is another name for a Vector inside of a Vector. What is the name of this construct? Would it be a Constructor Vector? I think this is a trick question my teacher is asking...

View 4 Replies View Related

C++ :: SDL Deleting From Vector

Apr 13, 2013

Simple rect collision detection

bool check_collision(SDL_Rect *box1, SDL_Rect *box2){
if(box1->x+box1->w<=box2->x)return false;
if(box1->x>=box2->x+box2->w)return false;
if(box1->y+box1->h<=box2->y)return false;
if(box1->y>=box2->y+box2->h)return false;

return true;

[Code] ...

The order of the game is of course standard.

1.handle input
2. handle logic
3. render
4. update

It's all pretty simple and straight forward, but oftentimes (not always) when the weapon hits the asteroid, the program crashes. If for example I turn off the delete main_weapon[i] and main_weapon.erase(main_weapon.begin()+i); the program works perfectly, but of course the bullets go right though the asteroid object, which is not what I want. It's only the weapon deletion which is causing no end of trouble.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved