Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

erase() just removes an object from the vector, it does not delete the object. I would write that releaseAll() function like this:

static void releaseAll(){
   std::vector<ManagedClass*>::iterator first = track.begin()
   while( first != track.end() )
   {
         delete *first;
         first++;
   }
   track.erase(track.begin(),track.end());
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you are just overcomplicating that entire process. The solution is a lot simpler than what you have posted. First, toss out that GetString() function because its not necessary. This is all there is to it.

string line;
int counter = 0;
while( std::getline(datafile, line) )
{
      std::stringstream str(line);
      str >> AdmNum[counter] >> states[counter];
      counter++;
}

It would be better is you created a structure with the int and string, then made a vector of structures. That makes it a lot easier to keep the int and strings together, especially if you want to sort the arrays.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post the first two lines of the actual file

100 101something 102another 103yetanother

something like above?


Here is an example of how you might do it. This technique should work with an input stream instread of using stringstream in my example

#include <string>
#include <sstream>
#include <iostream>
using namespace std;


int main()
{
    int i;
    int arry[4] = {0};
    string strarray[3];
    string str = "100 101something 102another 103yetanother";
    stringstream ss(str);
    ss >> arry[0];
    for(i = 0; i < 3; i++)
    {
        ss >>arry[i+1] >> strarray[i];
    }
    
    for(i = 0; i < 3; i++)
    {
        cout << arry[i+1] << " " << strarray[i] << "\n";
            
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is a good explaination. Whether to use using namespace std; or not to use it is more of a personal preference than anything else. There is no right or wrong way to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code I posed only accesses 8 of the int's 32 bits (assuming 32-it compiler).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

write a TSR assuming the os is MS-DOS 6.X or earlier.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It instantiates two arrays, d with 5,000 elements and f with 5,000 elements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>BUT STILL ALL THESE Replies ARE NOT helping me
BECAUSE YOU ARE NOT LISTENING!

Here is an example how to do it.

#include <fstream>
using namespace std;


union myunion
{
    unsigned int x;
    struct mystruct
    {
        unsigned int bit1:1;
        unsigned int bit3:1;
        unsigned int bit4:1;
        unsigned int bit5:1;
        unsigned int bit6:1;
        unsigned int bit7:1;
        unsigned int bit8: 1;
    }x2;
};

int main()
{
    myunion u;
    u.x = 123;
    ofstream out("data.txt");
    out << u.x;
    out.close();
    ifstream in("data.txt");
    int >> u.x;
    in.close();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In general bit fields are useless part of C (and C++) language (next to nothing).
Better get it out of your head and go on...

2. Alas, I have used bit fields over 30 years ago in C...

So ... bit fields aren't useless aftersll :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>In that case all "right" snippets above are wrong, array_of_floats pointer points to the location with invalid (for floats) memory alignment

I agree, and I mentioned the alignment problem that would have to be fixed in order for the code snippet I posted to be actually useful. There are probably only a handfull of reasons to use that technique, and certain no reason at all for college-level students.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Google is your friend if you bother to use it at all. Read this and this

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>>> it seems you have to manually use the first argument.
Alright -- I guess I misunderstood what you meant. You don't have to use the first argument at all if you don't want to. But yes, if you want the first argument displayed then you have to do it yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You need to post code and the first fiew error messages (certainly NOT all 88 errors!). I just compiled this with VC++ 2008 Express without error

struct data
{
int x,y;
double s,w,e,d;
}d[5000],f[5000];


int main()
{ 

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have posted the answer yesterday but DaniWeb site discard it (why?).

My guess is that you forgot to hit the Submit Reply button. I have never seen someone's post just disappear without reason.

In general bit fields are useless part of C (and C++) language (next to nothing).
Better get it out of your head and go on...

Strongly disagree. Just because YOU have not used them (yet) doesn't mean others haven't.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Now you can use the usual union membership operator to assign values to individual fields:

NO YOU CAN'T. The union is used to assign the same memory location to several different POD (Plain Old Data) type objects. All the objects in the union below occupy the same space, and the size of the union is the size of its largest member. Example:

union myunion
{
     int a;
     short b;
     long c;
     double d;
     char f[8];
};

Here is more information about unions.

c++ bit fields are completly different animal. Read this article for explaination about how to use them. You will normally want to put bit fields in a structure.


>>is there any way by which I am able to overload extraction >> operator without
that error and without changing any part of code?

No. You will have to change the code to provide an extraction operator for Nibble.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually its not necessary to do more than one malloc

char *memory_block = malloc(sizeof(struct str_type)+sizeof(float)*num_of_float);
struct str_type *ptr_str_type = (struct str_type *)memory_block;
float *array_of_floats = (float *)(memory_block + sizeof(struct str_type));

The above array of floats can be optimized by aligning the array on the mathine's word boundry. That involves adding a bit more memory to memory_block and adjusting the start of the float array.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Generation Y will be the downfall of America.

The older generation has ALWAYS said that about the younger generations. Yet, we are still here :)

They certainly are good at ruining music.

There has not been a good piece of music written since 1961 with the sole exception of what you find in movies such as Sound Of Music (1965) and Grease (1978)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want your own memory block to act like the memory pool allocated by malloc() then you have to write some sort of memory management functions for the pool. Use malloc() only to allocate the initial memory block. After that your program has to keep track of free blocks and used blocks. AFAIK this is normally done by use of linked list. It can get a bit complicated.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My guess is that you included very old header file <iostream.h>. M$ compilers, as well as ALL other modern compilers use the current <iostream> (without .h extension) then code the using statements

#include <iopstream>
using std::cout;
using std::cin;
// etc

If your program is using a lot of those, then you can do it like this

#include <iostream>

using namespace std;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i am getting right result which means my coding is absolutely correct.
Not necessarily. Did you write pure ANSI C or C++ ? Or did you mix it in with Borland-specific functions ? Just because it compiles with Borland doesn't mean diddly squat if it can't be compiled with other compilers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If course you can't declare the same object more than once. In your initial post, when you said it doesn't work, what exactly do you mean by that? What makes you believe it doesn't work?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ok, you stated what the program is supposed to do, now tell us what you did to solve it. Don't know where to start? Try this:

int main()
{
   // your code goes here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its hard to say why that code isn't working, since we have no idea what Output and Ode are -- resumeably c++ classes. That would normally not be a problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why do you have all that MFC stuff in a console program?

line 54 is illegal. You can't do that -- its not accessing the memory location on a floppy but a memory location somewhere on your computer's RAM.

How to do what you want: I don't know.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

declare a character array that is large enough to contain the filename and all the arguments, then pass that to the system() function. Example:

char command[512] = {0};
char filename[255];
printf("Enter a file name\n");
fgets(filename,sizeof(filename),stdin);
// remove '\n' 
filename[strlen(filename)-1] = 0;
sprintf(command,"HandBrakeCLI -i /dev/hdc -o /root/%s -b 1024 -B 128 -R 48 -E faac -f mp4 -w 368 -l 208 -m", filename);
system(command);

You may have to adjust the above if filename contains spaces.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

std::string is declared in the header file <string>, not <string.h>. The error you reported is because you failed to include <string> in your program.

strcat: You failed to declare name large enough to hold both last name and first name, so if you enter last name with 18 characters and first name with more than 2 characters strcat() will scribble all over memory, causeing great harm to your program.

The best solution is to learn to use std::string class in your c++ programs, unless of course the intent is to learn character arrays.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is your computer running antivirus program ? Is it up-to-date?

Check here to see if there is a program that will start on bootup:
C:\Documents and Settings\All Users\Start Menu\Programs\Startup

Also similar directory, but with your user name instead of "All Users".

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post code because its a little hard for me to see what you wrote on your computer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yah i want to open a file file1.dat write content into it ..close and oen a new file with a name file2.dat write content n close it .. and continue this !!

Great :) I already posted an example of exactly that algorithm. One problem may be how to get a list of the filenames. Do you want to create them at runtime, such as appending a number after a commen name? Or get a list of existing filenames ? Or something else ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can only open one file at a time -- C and C++ languages do not support opening multiple files with the same FILE pointer or c++ stream at the same time. So you have to open a file, do something, close the file, then repeat that process for each filename.

You can, however have an array of FILE pointers all open at the same time, but each one can only open one file. That's usually a pretty waste of program resources and not normally recommended except when there are only a couple of files that have to be open at the same time.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Can someone help me out with this .. in C++??
Help? yes. c++ no. fopen() is a C function, not C++;

char *filenames[] = {"file1","file2","file3",NULL};

for(int i = 0; filenames[i] != NULL; i++)
{
    FILE* fp = fopen(filenames[i], "r");
    // do something

    // now close the file
    fclose(fp);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post code. you need to store the filename in either a character array or std::string. Example:

#include <iostream>
#include <string>
using namespace std;

int main()
{
     std::string filename;
     cout << "Enter a filename\n";
     getline(cin, filename);
     cout << filename << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The best part of arguing with your GF is making up and making out. Don't let disagreements linger very long, especially never ever over night. When the sun sets its time for YOU to resolve all disputes. A lasting relationship means you tell your partner "I'm sorry."

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

so if you have address of int - you can try this :)

int * money = (int*)0x7ffd8000;
*money = 666;

Read threads before opening mouth and inserting foot :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean you want the program to read a *.c or *.cpp file then print all the function names ?

Start out with a very simple program that just opens the file and prints out each line. Post your code for that much and then we can talk about the rest of the program requirements.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see some of these google links.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In MS-Windows and *nix each process (program) has its own address space, and the address in one program can not normally be changed by another program. That is one of the security features of the operating systems. Just because you printed out the address of a variable in program A doesn't mean you can use that address in program B because in program B that address might point to a completly different thing (such as code) in program B's address space, or it might not be the address of anything at all.

That address is not relative to the operating system but relative to the program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> it seems you have to manually use the first argument.
No you don't.

>>is it important for the argument to be const char*?
No. The first argument can be any POD you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What makes you think he's gone?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <iostream>
#include <iomanip>
#include <ctime>
#include <windows.h>
using namespace std;


int main()
{
    DWORD ticks = GetTickCount() / 1000;
    cout << ticks << "\n";
    time_t now = time(0);
    struct tm* tm = localtime(&now);
    tm->tm_sec -= ticks;
    now = mktime(tm);
    cout << setw(2) << setfill('0') << tm->tm_mon << ":" << setw(2) << setfill('0') << 
        tm->tm_mday << ":" << setw(4) <<tm->tm_year + 1900 << "  ";
    cout << setw(2) << setfill('0') << tm->tm_hour << "/" << 
        setw(2) << setfill('0') << tm->tm_min << "/" << setw(2) << setfill('0') << tm->tm_sec << "\n";

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

system boot time is the value returned by GetTickCount(). If you want to know the actual date/time, call time() function in time.h, then localtime() to get struct tm pointer. From that subtract the number of seconds returned by GetTickCount(), pass that result to mktime() (from time.h) which will do all the math needed to normalize the date/time in struct tm. Volla -- you have the actual date/time the system was booted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you leave the 3d message box in the main thread then you don't have to call that WaitForSingleObject() function, and the program don't exit immediatey. But the program will exit immediately if you press the Ok button in the MessageBox that appears in the main thread. Note that you can create as many message boxes as you want with the posted code. If you want four MessageBoxes then just call CreateThread() another time.

As I said in my previous post -- I already showed you how to do it. All you have to do is ass more CreateThread() function calls.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use setw() to force column width. cout << setw(2) << 12 << setw(6) << "Hello";

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It is possible to pass C character arrays as variable arguments, just access them similar to how you would an integer. Your function needs to know the data types of the parameters. If some are integers and other are pointers, you program will have to know about that. There is nothing in vargs that will tell you the data types or types of pointers.

Your function also needs some way to know how many variable parameters have been passed. One way to do that is, for pointers, make the last pointer NULL

#include <stdarg.h>
#include <iostream>
using namespace std;

void battleShip(const char* what,...)
{
    va_list p;
    va_start(p, what);
    char* who;
    while((who = va_arg(p,char*)) != NULL)
        cout <<  who << "!.." << endl;

    va_end(p);
}

void main()
{
    
    battleShip("Air-raid alert!","One","Two","Three",NULL);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Not saying you should use it, but one way is to remake the structure with the same variable types and sizes, but leave all the members public, heres an exmaple.

That's not a reasonable solution. If class A contains hundreds of lines of code/methods, do you really intend to duplicate all of them in class B, then try to make class B act like class A? Sorry, but IMO that is just a lousy suggestion.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Who is jbennet anyway?

click here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ahh damn it, I'm not included...

Sorry, but I selected the list from the top 10 (or so) posters. I would have like to have added more people because there are a lot of good avatars, but there is a max of 10. I didn't want to limit the list to mods because there are lots of other good avatars too and I didn't want this to turn into a popularity contest among mods.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I already did.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

"hard" is a relative term -- if you're a snot nosed brat who'se mommy always did things for you, then yes c++ might be hard to learn. Learning something takes more time for some people than for others, but stick to it an it will sink into your brain.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> I need to access but can't because it is declared as private...
In MyClassB write a get() function that returns the value of the private variable, and you can also write a put() variable that lets you change it.

>>Could anyone also explain what & does?
Depends on the context -- when used in the parameter to a function it is a reference operator. If you don't know what that is then look it up in your text book.