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

I know ^.^ I changed it as fast as I could, way before you posted.

where did no change it? Looks the same to me.

include <iostream>

namespace A {
   int var = 10; <<< error here
};

namespace B {
   int var = 20; <<< error here
};

using namespace A; <<< error here
using namespace B; <<< error here
<snip>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

williamhemswort:
A and B are not namespaces. They are c++ classes. You can not give a class the same name as a namespace. And lines 4 and 8 of you code is wrong.

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

>>nd unfortunately it doesn't seem as if clear or resize properly deletes or destructs the pointers

>>I'm sorry... where did I use erase? O_O
clear() is the same as erase(begin, end)

>>I got a lot of errors from attempting to cast the object referenced by the iterator to a ManagedClass
No casting necessary. I did not use a cast in the code I posted.

Alex Edwards commented: Thanks a million =) +3
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

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

>>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

>>>> 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

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

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

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

>> 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

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

>>It jumps from requesting a tool name to requesting the number in stock
That is the typical behavior of some previous cin for entering a number because when you enter a number the program leaves the '\n' (Enter key) in the keyboard buffer, then when entering a string cin thinks the Enter key is pressed. To solve that problem you need to clear the keyboard buffer of all its contents -- please read this thread about how to do that. You should put that code snipped after numeric data input.

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

SQL is a language, MYSQL is an implementation of that language. There are many different database engines that support the SQL language -- MySQL is only one of them. Others are Oracle, Sybase, and Microsoft SQL Server.

Shanti C commented: exaclty... +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If thats all your forum has for me then I'll leave, disappointed.

Bye. We aren't here to write your programs for you. Only you can do that.

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

So - where do I start? Please help me to do this.

We have already done that too, and I'm not going to repeat what everyone has told you. Go back and read those posts yourself, then take what they said and run with it.

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

>>And if any of you think I'm completely crazy
Yup. Remember, I didn't say that, you did :)

>> Please let me know that your thoughts are
I think we already have done. that.

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

>>I take offense to this.
You are supposed to :) Would you start building a house if you don't know the difference between a hammer and a screwdriver ?

Start at the beginning, learn to crawl before you walk. Buy an introduction to c or c++ book and start reading from page 1. There are many suggestions for good books in one of the Read Me threads at beginning of this c++ board. Read those threads, buy the book, then begin studying. After a couple years of studying you will probably be ready to tackle that project of yours.

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

>>Ok - there's nothing like a BIG challenge to start off my exploration into programming
HaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHa HaHaHaHaHaHaHaHaHaHaHaHa HaHaHaHaHaHaHaHaHaHaHaHa

Sorry, but I can't stop laughing! You don't know a thing about programming, yet you want to do WHAT! HaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHa

I really should move this into Geek's Lounge because its so funny -- you got to be joking, right? HaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHa HaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHaHa

VilePlecenta commented: meh +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This works for me

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


typedef std::vector<string> String1D;
typedef std::vector<String1D> String2D;
typedef std::vector<String2D> String3D;

int main()
{
    String3D vector1;	
    String3D::iterator OneDStart = vector1.begin();
    String3D::iterator OneDEnd = vector1.end();
  
    for ( ; OneDStart != OneDEnd; OneDStart++ ) 
    {  //1D
        String2D::iterator TwoDStart = OneDStart->begin();
        String2D::iterator TwoDEnd = OneDStart->end();
        for ( ; TwoDStart != TwoDEnd; TwoDStart++ )
        {   //2D
            String1D::iterator ThreeDStart = TwoDStart->begin();
            String1D::iterator ThreeDEnd = TwoDEnd->end();
            for ( ; ThreeDStart != ThreeDEnd; ThreeDStart++ )
            {   //3D


            } //1D
        } //2D
    } //3D
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) The while statement is incorrect

while( inData>>lastname>>firstname>>identity[number] )
{
   // other code here
}

2) you don't want that i loop because it is attempting to read (rows*cols) number of numbers for each name. All you want it to do is read the columns for each name.

int i = 0;
while( inData>>lastname>>firstname>>identity[number] )
{
     sum = 0;
     for(j = 0; j < cols; j++)
     {
          inData >> numbers[i][j];
          sum += numbers[i][j];
    }
    cout << sum << "\n";
    i++;
    number++;
}

3) you are keeping all the integers and floats in an array for all names, but you don't keep the names ? Any reason for doing that? If you don't need the names then why not just toss the numbers for those names too?

4) rename either number or numbers to something else because they are confusing.

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

There really is no way to tell if the file is still opened other than attempt to open it in your program. If open fails, wait a little bit then try again. stay in that loop until open succeeds or some timeout value expires.

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

1) Depends on the compiler and whether you compile the program for debug or release. Most modern compiler will make them the same code, despite the errors in the code snippets you posted.

2) Speed has nothing to do with it -- the { and } are there to block lines of code. I like to use { and } even with one liners for readability and ease of future enhancements.

3) One is not more efficient than the other -- is readability and maintainability that counts. Use boolean true/false whereever it makes sense to do that.

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

How about this one? But this has the danget of writing outside the bounds of the array, so you need to add more checkiing.

rows = cols = 0;
while( infile >> numbers[rows][cols])
{
    cols++;
    if(cols > 7)
    {
        cols = 0;
        rows++;
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>fflush(stdin);
Nonstandard. fflush() is only for use with output streams. Some compilers has added support for input streams, but such implementations are non standard. Read this and this too

>>No I cannot do this because then even record can have its own size and it will not be consistent to print the records and align them.
Huh? But what I posted was just what you were trying to do. All I did was delete the need to calculate the length -- strnlen() will do that.

>>My code is the following but it does not work because apparently getline only works with arrays?
There are two forms of getline: one for std::string and the other for character arrays.

std::string name;
getline(cin, name);

or
char name[20];
cin.getline(name, sizeof(name));

>>If I stay to the following code then I have the issue where it keeps previous input and tags it on to the end of the array
If you are experience that problem then there is something else wrong because getline() doesn't work that way.

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

you are doing too much work!

int main()
{
    char name[10] = {0};

   strncpy(name,"How Now Brown Cow", sizeof(name));
   name[sizeof(name)-1] = 0;
   cout << name << "\n";

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

That pointer is used to create a linked list of structures -- each pointer points to another structure in the list. Study linked lists and you will find out how all that works. There are many tutorials available, such as this one.

tzushky commented: Great tutorial...Thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>3. Better use tabs \t to adjust columns in all trailing printfs.
That can easily screw up the spacing. Better to use printf() correctly, such as printf("%-10.10s%15d%15d%15d\n", n1, g1, w1, p1); The above will insure consistent spacing

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

>>You mean that the client files can only be compiled with the test project ? I
Yes, either the test project or your own program. The test project just show you how to incorporate the client files in your own program. That's the general way of doing it in all the projects you see at that web site.

I suppose if you want to use those client files in serveral different projects then you could compile them into a library (*.lib or *.a) so that they don't have to be compiled with each project. But that's up to you if you want to do it.

>>Is thats it ?
Yes, you got it :)

manzoor commented: Thanks for helping out so fast +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ShowFile() is coded incorrectly. This is how to read the file one character at a time. This will only read the first sizeof(s) characters, so if the file consists of more lines it may not read the whole file.

memset(s, 0, sizeof(s)); // clear the array of all junk data
     i = 0;
     while(f1 >> s[i] && i < (sizeof(s)-1))
     {
           cout << s[i];
           i++;
      }

But a much easier way to code it and it will read the whole file regardless of how may line the file contains.:

while( f1.getline(s, sizeof(s)) )
  {
      cout << s << "\n";
  }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

since you did not declare the using clase you will have to declare the namespace in which Func() exists, that is a::Funct()

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

You can not compile the client files by themselves -- see the test project (the third download). The files in that client download are intended to be incorporated into your own project which you want to add the looging feature.

>>Do you want to permanently remove the source control bindings from the projects?"
The project files require VC++ 6.0 compiler and you are attempting to compile them with a newer compiler. If you are using one of the Express versions such as VC++ 2008 Express then it won't work because the Express versions don't support MFC.

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

Here is the output I get

Empezar?
 4 - si
 5 - no

There are quite a few compiler warnings -- conversion from float to int may loose data. And a couple of uninitialized variables are used.

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

MS-Windows is not a real-time operating system, so no matter what you try the signals might or might not arrive to your program on time. You might try the Communications Resources link

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

Read this and follow the links

Also you might read some of these google links

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

line 10: That won't work because the vector is an empty vector. Wait until you get ready to use the iterator before assigning it to begin().

you could code that j loop using an iterator instead of an int counter

vector<CObject>::iterator it;
for(it = group.begin(); it != group.end(); it++)
{
      if (strcmp(identifier, it->getID()) == 0) 
      {
             group.erase(it);
             break;
       }
}

If you make getID() return std::string instead of char* you don't need to call strcmp().

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

Get it here link found on wiki scroll all the way to the bottom of the page and you will see External Links. There is also a link to User's Guide which might, or might not, answer Ron's question. Since that compiler was written for MS-DOS 6.X and earlier its unlikely it will support printers on any version of MS-Windows.

If you want to learn vb, forget about GWBASIC and learn VB 2008 Express, you will like the results a lot better.

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

I almost never give out negative rep in technical forums because I don't want to destroy anyone's reputation. I do give it out occasionally in geek's lounge because it doesn't affect overall rep points there. The rep for mods works the same as anyone else's, and the last time I heard it was 1/2 for negative rep.

The main reason I have such a large rep power is because of my huge post count. You get more rep for every 1,000 posts. And the more you post and participate in the technical boards the more frequently other members will give you good rep (assuming you post positive instead of negative things). My rep count doesn't mean I'm a better programmer than either Narue or Salem (which I don't think I am) ... it only means I participate in the forums more.

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

dump that old version of basic and get the latest-and-greatest free Visual Basic .NET

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

What you are learning from that book is the c++ language itself. What you see in the VC++ Forms code is just an implementation of c++. You need to know the c++ concepts before you will understand managed code programming. And yes, there are books written to teach managed c++, and here are a few google links that might help you if you have not already seen them. If you want to get into Windows Forms then it would be worth the money to buy a good book that covers that subject.

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

I got that *.zip file and tried to compile it, but Dev-C++ reports error that it cannot exec 'cc1'. It compiles the *.cpp files ok, but pukes at the resource file(s).

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

You should be asking these people. I don't think Dev-C++ knows how to compile the resource files, but there are several free resource compilers available via google.