34 Topics

Member Avatar for
Member Avatar for nathan.pavlovsky

Hello programmers! I have been working on STL algorithms for some time now as a beginner, and I started doing an exercise, among which is the task of `use the fill algorithm to fill the entire array of strings named items with "hello"`. My code for this is below: // …

Member Avatar for nathan.pavlovsky
0
1K
Member Avatar for Auroch

Hello everybody. I'm trying to write program with vectors and iterators. Coordinates X and Y are entered from keyboard (as structure) and placed in vector of points. It's necessary to display coordinates with maximal X and Y. This code was compiled but not display maximal X. What should I change? …

Member Avatar for Lucaci Andrew
0
274
Member Avatar for Auroch

Hello funs2code! I have the following problem. I need to count the number of occurrences of a concrete word in a text file. I've tried to count the number of occurrences of each word at first. The following code has no errors but it isn't working! When I type in …

Member Avatar for Auroch
0
361
Member Avatar for jkhippie

#include <memory> #include <deque> void MyFunc { std::deque< std::shared_ptr< Sprite* > > SpriteList; func_to_fill_deque( SpriteList ); for( auto i = SpriteList.begin(), end = SpriteList.end(); i != end; i++ ) { SpriteList[ i ]->spriteFunc(); // doesn't work SpriteList.at( i )->spriteFunc(); // also doesn't work } } void func_to_fill_deque( std::deque< std::shared_ptr< Sprite* …

Member Avatar for jkhippie
0
2K
Member Avatar for Pyler
Member Avatar for Pyler

I'm implementing a generi method that's supposed to traverse a binary tree in PostOrder but when I attempt to use it, the Iterator doesn't work as It should when I attempt to use ot on a Binary Tree, can anyone spot my mistake in the code? Thanks. The method makes …

Member Avatar for iamthwee
0
216
Member Avatar for admiri92
Member Avatar for Moschops
0
249
Member Avatar for Derek_4

I know I am probably over thinking this but I cannot seem to figure this out. I am trying to check if the value is null and if not to continue. /** * */ public Item getItem(String theItem) { Iterator iter = myItems.iterator(); while(iter.hasNext()) { Item anItem = (Item) iter.next(); …

Member Avatar for sebastianedu
0
294
Member Avatar for jonathan710

// Expect to print values of arr[0] to arr[4] #include <iostream> #include <vector> using namespace std; int main() { vector<int *> ptrList; int arr[] = { 0, 10, 20, 30, 40 }; int * ptrArr = arr; for( int i=0; i< 5; i++ ) { ptrList.push_back( ptrArr+i ); } vector<int …

Member Avatar for nullptr
0
255
Member Avatar for jonathan710

So I was asked to solve this question...however when i compile it, it doesn't work...could somebody tell me what's wrong and how to solve it (im guessing it's something to do with overloading since my lecturer was talking abt it just before this was given)? thanks a lot! #include <iostream> …

Member Avatar for DeanMSands3
0
265
Member Avatar for ktsangop

Hello everyone! I would like your help regarding this: I have a tuple vector which i must iterate through, and accessing the vector data to decide wether to erase or not the current vector element. My code : typedef tuple <int, CString, int, int> pc_data; vector <pc_data> pc_vec; //Assume that …

Member Avatar for ktsangop
0
6K
Member Avatar for Xorlium

Hello! I'm writing some mathematical iterators over some big classes that I don't want to store in memory at all, but I still want to be able to iterate through them. As an example (but I have a few of these), think of a class `Combinations({0,1,2...7}, 3)`, which means I …

Member Avatar for Xorlium
1
313
Member Avatar for ray.tan.507

I was doing some exercise from C++ Primer and one of them required us to copy a set of value from array into a vector container. Then, we are suppose to remove all the even numbers from the vector container. Hoever, when I tried to display them out by incrementing …

Member Avatar for Nick Evan
0
201
Member Avatar for cdsr

Alright so I've been struggling to find the error but I simply can't. Given the following code: #include <iostream> #include <vector> enum ScriptType { SCRIPT_TYPE_CREATURE_SCRIPT, SCRIPT_TYPE_PLAYER_SCRIPT }; class Script { private: ScriptType type; public: Script(ScriptType type) : type(type) { } ScriptType getScriptType() const { return type; } }; class CreatureScript …

Member Avatar for cdsr
0
294
Member Avatar for AznWun

Hey guys, I've tried writing code to reverse my sentence, but I keep getting an error in my for loop saying "Expected Expression". Also, should the asterisk go after the "modify" in my code? I'm not sure how pointers are exactly supposed to work and I haven't been given any …

Member Avatar for ravenous
0
316
Member Avatar for FUTURECompEng

I am trying to input an int into the end of a singly linked list. I have already created the code to put a number at the end of the list but when I go to print it out, it only prints out (in my test class) the int that …

Member Avatar for jalpesh_007
0
303
Member Avatar for jalpesh_007

Dear all, I have stuck with one problem. I have taken one Hashmap, Performing some input operation,remove operation on it. So after performing remove operation, i want value of 2 successive key in two different array. Also i want to match 1st key's value with all other keys' value. Like …

Member Avatar for JamesCherrill
-1
1K
Member Avatar for Ararat

I'm trying to compare the element pointed by an iterator to an integer, but so far i haven't had any luck in doing so. please correct whatever i'm doing wrong. Thank you. vector<int>::iterator y; for (int i = 0;i<n2;i++) { cin>>temp; cnt = 0; y = lower_bound(a.begin(),a.end(),temp); if (*y == …

Member Avatar for Ararat
0
1K
Member Avatar for arathy nair

Hi all, I actually need to use a sorted map.So i tried using Tree Map.But the problem is that This works well with sort key having values upto 9. With more than 10 items I see abrupt results with sort key arranged in the order = 1, 10, 11,12,--------17, 2, …

Member Avatar for JamesCherrill
0
220
Member Avatar for sonicx2218

So my java class is a joke, and we're expected to learn how to do our assignments via the web...I'm a hard worker, but I'm just not good at this. [Assignment pic](http://oi50.tinypic.com/aw3zx2.jpg) There's the assignment image. I think i got how to do the first part with the adding random …

Member Avatar for sonicx2218
0
543
Member Avatar for sonicx2218

Hey bros. I made a program that prints out random numbers in a linked list. I want to have the index number next to each of the random numbers in the list. I guess for example like: 1 25 2 123 3 56 ect. Here's m program so far, and …

Member Avatar for NormR1
0
329
Member Avatar for phummon

Hola code gurus, I’m wondering if there’s a way to use a string to access a specific item in a matrix of int[X]. I have a program which uses enums as iterators to reference a large amount of data. To select an item in the matrix, the user will enter …

Member Avatar for phummon
0
318
Member Avatar for alenD

Hi all, I am doing something like this int f(){ umap::iterator p = mmap.find(s); if(p != mmap.end()){ ....... } } My memory usage is somehow constantly increasing. While exiting the function do I need explicitly delete the iterator p? Thanks in advance, _alen

Member Avatar for MastAvalons
0
583
Member Avatar for mzimmers

Hi, all - I'm relatively new to iterators, and to template functions, so I suppose it was inevitable that the first time I tried to combine them, I'd run into a problem. Here's the function: [CODE]template <class T> int getVectort(ifstream & s, long nbrCells, typename vector<T>::iterator iter) { int rc …

Member Avatar for mzimmers
0
613
Member Avatar for sdragon

Hi Everyone, I'm new here and also new in using Java. I want to make an iterator without using the default methods hasNext, hasPrevious. Here is what I've already done using the default methods: [CODE]import java.util.*; public class HomeIterator{ public static void main(String[] args) { int i = 0; ArrayList …

Member Avatar for sdragon
0
267
Member Avatar for megatron21

I am having hard time understanding what the problem is with my code here. Basically I have a map that contains Key objects as the key, and Block* as the value. The point of this for loop is to print out the values that the key contains on to the …

Member Avatar for megatron21
0
251
Member Avatar for Coffee_Table

I am trying to run what i thought was a pretty basic program to solve a problem concerning strings (besides the point). It turns out that my algorithm works properly but i am stuck on a detail; the following segment of code is the problem: [CODE] int cases; string line; …

Member Avatar for Coffee_Table
0
585
Member Avatar for stemiros

Hi, I have a list of base types which stores multiple derived types. The following code shows a simplified setup. [CODE]#include "Base.h" #include "DerivedA.h" #include "DerivedB.h" #include <iostream> #include <list> void main() { std::list<Base*> base; std::list<Base*> *basePointer = &base; for (int i = 0; i < 10; i++) { basePointer->push_back(new …

Member Avatar for mrinal.s2008
0
2K
Member Avatar for rhuffman8

I just started looking at iterators in my C++ class and don't think I fully understand enough about them to actually create one. I need to add an iterator to this doubly linked list program: [CODE]#ifndef CSLIST_H #define CSLIST_H #include <iostream> #include <cstdlib> using namespace std; template <class T> struct …

Member Avatar for rhuffman8
0
276
Member Avatar for fibbo

Hey, it's me again. Again with a topic that has been covered here but reading through the old threads didnt help me to solve my problem. And I am pretty clueless at the moment. Consider the class passenger_queue with 2 functions, namely: [CODE]int passenger_queue::get_passengers_waiting() const { // Insert your code …

Member Avatar for fibbo
0
7K

The End.