C/C++ :: Vector Content Goes Away As Soon As Method Ends

Apr 2, 2015

I have this class, Prenumeratorius, it represents a subsriber in this context. Then I have a class Leidinys, which represents a newspaper:

class Leidinys {
private:
string kodas;
string pavadinimas;
double vienetoKaina;

[Code] .....

So in while loop it just reads data, Then I create Prenumeratorius object and store data in it, then I want to add it to correct place by using DėtiPrenumeratorių(), I will show it's content in just a moment. And the last method call - I just add element to another two way list of all subscribers.

So here is content of DėtiPrenumeratorių():

void LeidiniuSarasas::D/>ėtiPrenumeratorių(string kodas, Prenumeratorius &P) {
for(LeidiniuMazgas *dd = p; dd != NULL; dd = dd->Pirmyn()) {
if(dd->Imti().ImtiKodą() == kodas) {
dd->Imti().DėtiPrenumeratorių(P);
}
}
}

It just loops through all newspaprers and searches for the match. I actually tested this method, it works just fine, the problem is one step further:

As you can see, it calls another DėtiPrenumeratorių() method, this time that method puts Prenumeratorius in the vector I showed at the beginning.

The problem is, that when that method is over, vector's content dissapears, I debuged program and saw that, but I can't recognize what is wrong, I added & to all of my method's headers where it accepts that Prenumeratorius object. The same algorithm used to work with one way list.

View 4 Replies


ADVERTISEMENT

C++ :: Getting A Large String Vector For File Content Manipulation?

Dec 10, 2013

I need a large string vector for file content manipulation.

v1.max_size() gives me 153 391 689.

But if I make a test by looping a vector pushing back strings it crashes around 16 - 26 000 000 though I still have a lot of ram (1GB left).

How come and why isn't vector size limited by ram instead?

View 11 Replies View Related

C++ :: Method Passes Values To A Vector But It Stays Empty?

Dec 10, 2014

I have two classes, one class requests another class to populate a vector with some data using getAvailableStreams() method:

vector<AutoRefPtr<ManifestStream> > availableStreams;
std::cout << "now asking for streams." << std::endl;
manifest->getAvailableStreams(&availableStreams);
std::cout << "got so many streams: " << availableStreams.size() << std::endl;

The other class passes another pre-populated vector back:

virtual RESULT getAvailableStreams(std::vector< AutoRefPtr<ManifestStream> >* availableStreams) {
availableStreams = static_cast<std::vector< AutoRefPtr<ManifestStream> >* >(myStreams); //myStreams contains 1 stream

I'm also adding a stream here directly just for testing purposes:

ManifestStream stream2;
availableStreams->push_back(AutoRefPtr<ManifestStream>(&stream2));
std::cout << "calling getAvailableStreams. Giving so many streams: " << myStreams->size() << ", " <<
availableStreams->size() << std::endl;
return result_OK;
}

If I run the code, I can see the following logs:

Now asking for streams. Calling getAvailableStreams.
Giving so many streams: 2, 2
got so many streams: 0

Why am I getting 0 streams when I exist the method? I just had 2 streams in availableStreams while I was inside the method, where have they disappeared?

View 6 Replies View Related

C++ :: How To Play Sound When The Program Ends

Jul 16, 2013

How can I play sound when the program ends? I am using Windows 7.

View 15 Replies View Related

C :: Fscanf Data To Array - It Always Ends Up With Random Numbers

Apr 16, 2014

I am a very fresh c programme user, and need to fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code?

When I printf the array it always ends up with random numbers. Below is my programme which is just designed to read a doc and print it back out, as well as the text doc it is designed to read.

View 3 Replies View Related

C/C++ :: Exponents Solution Do Not Give Right Answer If Last Number Ends In 5

Mar 19, 2014

I have two unassigned variables A,B . My program goes as follows

#include <iostream>
#include <string>
#include <cmath>
#include <stdlib.h>  
using namespace std;    
bool die (const string & msg);  

[Code] ....

This a program that makes a calculator in which this is a small portion of it, all the exponent numbers work exceptfor anything ending in 5.

Examples go as follow 2^3=8, 3^2=9, 5^2=24

I want to why this happens, is it because they are unassigned variables?

View 1 Replies View Related

C :: Append Data To Array Of Structures In Memory Then Put In File When Program Ends

Dec 4, 2013

I have a program that stores health information the user inputs, one person at a time. The program works perfectly with the exception of storing the data...I need to open a file and read what health data it has in it already, if any, but store the new changes, and appended data to the array of structures, to the data in memory. All of the information is only saved back in the file once the program terminates. I'm not sure how to go about doing this, so I am also not sure what to put in the function for "Save and Exit" that the user can choose in order to exit the program.

Code:

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct strdatabase
{
char first[20];
char last[20];
char gender[2];

[Code]...

I tried playing around with this bit of code, but I'm not sure if I'm even on the right track.

Code:

FILE *fp;
fp = fopen ("students.txt","rb"); fseek(fp, 0, SEEK_END);
long pos = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *bytes = malloc(pos);
fread(bytes, pos, 1, fp);
fclose(fp);

View 9 Replies View Related

C++ :: Undefined Reference To (method Name) When Accessing Method In Static Library

Jan 17, 2013

I've been trying for more than one month to access a method found in a library called libcocosnas_static.a. I'm using Cocos2d-X version 2.0.4. The library has been used many times by my company to make games using cocos2d-1.0.1-x-0.12.0 without any problem.

This is what I've done:
1- I added the include paths of the library to both eclipse and Android.mk
2- Included the .h file using #include "NASPlatformUtil.h"
3- Added the libcocosnas_static.a file to the proj.androidobjlocalarmeabi folder
4- Added "LOCAL_WHOLE_STATIC_LIBRARIES += cocosnas_static" to the Android.mk file
5- Called the function using: NASPlatformUtil:: openUrl("http://xxx.xxx.com/");

I can right click on the function, click Open Declaration and get it without any problem, but the compiler keeps on giving me that dreaded error...

View 3 Replies View Related

C++ :: Pass Method Of Derived Class As Parameter To Another Method In Base Class?

Feb 2, 2015

I have a question similar to the one here: [URL] .....

The main difference is I would like to pass a method of derived class as a parameter to some other method in its template base class.

template <typename BaseType>
class Base {
public:
typedef void (Base::*Callback)(int A);

[Code] .....

The above is an example which does not compile. My compiler complains that the two BaseMethod() calls in DerivedMethod() are invalid uses of non-static member function.

Is this not possible to do, or is my syntax simply wrong? All I want is to be able to pass as an an argument to a method in the base class from the derived class some callback as a variable for the base class to invoke later.

View 2 Replies View Related

C++ :: Search For The Key Given A Content In Map?

Jan 7, 2014

In a C++ map, is there any way to search for the key given a content? Example:

I have this map:

map<int,string> myMap;
myMap[0] = "foo";

Is there any way that I can find the corresponding int, given the value "foo"?

cout << myMap.some_function("foo") <<endl;

Output: 0

View 3 Replies View Related

C :: Is There Way To See Binary Content Of File

Apr 3, 2013

I am using c to read and write contents of a file into other:

FILE *ptr;
status_t status;
uint32_t block_size, result;
uint32_t num_blocks;
char temp_buffer[1024];
}

[code]....

Is there way to see the binary content of this file.

View 2 Replies View Related

C :: Display Pointer Content

Oct 30, 2013

I wrote a code and I found a small problem with the display of the pointer

here is the code :

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {

[Code]....

View 5 Replies View Related

C++ :: How To Display Structure Content

Dec 17, 2014

I need to display all the content of the ( codedParams & modeParam ) in the next piece of code

struct SAOOffset {
SAOMode modeIdc; // SAOMode is an enumerator
Int typeIdc;
Int typeAuxInfo;
Int offset[MAX_NUM_SAO_CLASSES];
SAOOffset();
~SAOOffset();
Void reset();
const SAOOffset& operator= (const SAOOffset& src);

[Code] .....

View 1 Replies View Related

C# :: Adding More Than One Content To Scrollviewer

Apr 20, 2014

I'm trying to create an appointment time table.

I used a ListBox with each ListBoxItem representing 15 minutes. Now I want to add some kind of label/picture next to the Listbox to indicate the hours.

What I did was I got rid of the scrollbars and scrolling ability of the ListBox and I heightened to the max. THen I added it into a Scrollviewer to scroll up and down.

Now I also have a StackPanel with TextBlocks. Each TextBlock is an hour label.

I want to put that StackPanel into the Scrollviewer as well so it can scroll alongside the ListBox! But it seems the Scrollviewer can only have one "Content" in it.

A picture of my program:

Link to Dropbox pic

Here is my XAML so far:

(In this code my StackPanel is actually currently in Scrollview. I want to add my ListBox in as well...but I can't... />/>

<Grid>
<ScrollViewer Height="444" Width="350" Margin="834,145,10,182">
<StackPanel Height="1440" Width="101" HorizontalAlignment="Left" VerticalAlignment="Top">

[Code].....

View 3 Replies View Related

C :: Copy Variable Content To Clipboard?

Sep 3, 2014

In this example code:

Code:
printf ("
Type in 1st address: ");
scanf ("%x", &address1);
address1 = (address1 - number1) * 2;
printf ("
Result = %08X

", address1);

How can i copy the contents of var address1 onto the clipboard?

View 8 Replies View Related

C :: How To Write A Content Manager System (CMS)

Feb 17, 2014

how can i write a contact manager system(CMS) in c ?

View 2 Replies View Related

C++ :: RAM Disk And Pointer To Content In File

Mar 3, 2014

When we are using RAM DISK - the files are stored on the RAM. From what I understand (and saw many examples) in order to read data from file (the file which locate on the RAM) - I need to use the read function.

Is there a chance to get char* (or any pointer) to the content of the file without using the read function ?

If the file locate on the RAM, it seem that it is like I have a buffer on the RAM (like an array which was dynamic allocated) and in the case of a buffer on the ram -> we can use pointers to the data without reading all the data.

example:

class CDATA {
int nValue1;
int nValue2;
double dValue3;
double dValue4;
char achBuf[10];

[Code] .....

View 2 Replies View Related

C++ :: Adding Content To Window Using Ncurses

Aug 12, 2013

I'm makeing a card game with ncurses. I have all the card and player objects in order but i'm stuck trying to get the gui to work.

I'm using multiple windows for different players deck and pile. Now to the problem: I can get all the windows to show with borders in the console but i can't get any content printed in the windows and I rally can't see why!?

I have been reading the guide on [URL] but I don't get any further on the problem right now.

PS. the complete code incl. Makefile can be found at:
github.com/DanBrehmer/cardGame
#ifndef GUI_H
#define GUI_H
#include <ncurses.h>

[Code]....

View 3 Replies View Related

C++ :: How To Put String Content Into Source Code

May 23, 2013

I'm trying to write a program that prompts the user to enter a math expression (i.e 2*x + x*x) and a value of x. Then generate the value of y. My real question is: Is there a way to put the content of a string into the source code?

Example:

string math_function;
double x, y;
cout << "Enter the function: ";
getline(cin, math_function);

[Code] .....

View 4 Replies View Related

C++ :: Member Function To Shuffle Content?

Nov 14, 2014

Is there member functions for STL's like vector,list etc., to shuffle the content of that STL.

eg:

int arr[] = {1,2,3,4};
std::vector<int> v1(arr, arr+ sizeof(arr) / sizeof(int) );

now i need to shuffle the data randomly like

Now vector may contain {3,2,4,1} or {2,1,4,3} ...

I have taken vector as an example. let me know if there is any alternative way with other STL's

View 2 Replies View Related

C :: Appending Content In Middle Of A Text File

Sep 18, 2013

A user enters a query and other users reply to it. But it creates a problem here. After adding queries, if I wish to reply to query in between then it adds a redundant entry in file. 1st entry is the original query without reply and 2nd entry is the same query now with a reply added. I want only 1 entry of the query along with replies.Here is the code:

Code:

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include "var.c"
int check_count();
void add_query();
void add_reply();
}

[code]....

View 9 Replies View Related

C++ :: How To Read All Content From A Text File Into A String

Sep 24, 2013

I'm trying to read all content from a text file into a string. This is the code I'm using for it (I know there are other, maybe better ways to do it but I'd like to stick to this for now):

char* buffer;
std::string data;
FILE* fp = fopen("textfile.txt", "rb");
if (!fp) {
printf("Can't open file");

[Code] ....

So my problem is that I get an exception when I try to free the memory -> 0xC0000005: Access violation reading location 0x51366199

I even get the exception when I try to free it immediately after calloc() but why this is.

And if I use buffer = (char*)malloc(lSize); I don't get any exceptions.

So, why this fails and what I'm doing wrong.

View 14 Replies View Related

C++ :: How To Store Entire Content Of File In Variable

Jan 28, 2013

I would like to store the entire content of a file in a single c-string variable or in a standard string class variable. Is there a function that will do this for me? I am familiar with functions that get one character or one line at a time but I don't think I've encountered a function that gets the entire file. Does this function keep or disregard the end-of-line character? If no such function exists, I would write my own function to create and return such a variable.

View 4 Replies View Related

C# :: WPF / How To Check If Page Content Is Completely Rendered

Jan 13, 2014

In my program I have to load a page in a second window based on user's decision. This is how I do it:

case 1:
Page1 p1 = new Page1();
secondwindow.frame.Source = new Uri("p1.xaml", UriKind.Relative);
secondwindow.Show();
break;
case 2:
Page2 p2 = new Page2();
secondwindow.frame.Source = new Uri("p2.xaml", UriKind.Relative);
secondwindow.Show();
break;

The user should not be able to navigate between these two pages, and between choosing one or the other page, the user will have some interaction with the main window. For the user interaction with the main window, the second window gets hidden:

if (secondWindow != null)
{
secondwindow.Hide();
}

Now if the user selects the first page and and then the second page, when I show the second window, I can see the first page for a fraction of a second, and then second page gets rendered. I wanted to know if there is a way to make sure the rendering is complete before using:

secondwindow.Show();

View 5 Replies View Related

C# :: How To Represent A Table That Contains Dynamic Content In Header

Jun 2, 2014

I've attached an image that shows a basic table with dynamic content in the header.

Initially, I thought about using a datagrid. However, I can't use a datagrid because of the format of my data visually. The DataGrid would not allow me to have static and dynamic data inside my column headers.

You see anything I am displaying in brackets, {}, are being updated with results after I process some data in the backend. After the data analysis is done, the results are displayed based on an algorithm.

So, let's say for control1, for each family, it would indicate whether the data passed or failed. Then, in the rows themselves, it would update with choice 1 or choice 2 depending on the data generated.

So, the data that is in brackets shows properties being updated. I'm not sure what UserControl I can use to accommodate this kind of display.

View 13 Replies View Related

C/C++ :: Search In File And Extract Content Between 2 Strings

Jun 8, 2014

I need to develop a simple program, i have 2 variables (begin, end), and i need to search in a file, And extract the string between the Begin and the End variables to a new File, For Example:

my text file: file.txt:

some text here<StartHere>more text here</EndHere>text text

C++ Program:

//Declear 2 variables
strcpy_s(begin, string("<StartHere>").c_str());
strcpy_s(end, string("</EndHere>").c_str());

//And now, search in the Text file, And Extract the text between the begin string and the End string.
<...>

The Result should be: NewFile.txt with the content:

<StartHere>more text here</EndHere>

That's it!, Here is what i have for now:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
int ocurrences_count = 0;
int ocurrences2_count = 0;
char word[20]; //this array will save user input

[Code] ....

View 1 Replies View Related







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