Tom Gunn 1,164 Practically a Master Poster

You can still use system() if you want. All it does is pass the string to the command shell, so the string has to look like it would in the command prompt. For names with spaces, wrap the path in double quotations:

#include <iostream>
#include <string>
#include <cstdlib>

int main()
{
    using namespace std;

    string cmd = "type ";
    string filename;

    cout << "Type a filename: ";
    if (getline(cin, filename))
    {
        system((cmd + "\"" + filename + "\"").c_str());
    }
}
Tom Gunn 1,164 Practically a Master Poster

What compiler do you use?

Tom Gunn 1,164 Practically a Master Poster

In case of main function, if i forgot to write return 0; at the last, GCC compiler generates no error

If you rely on the compiler to point out every problem in your code, you will spend more time with the debugger than if you know the problem areas that go undiagnosed by compilers and always write code with your brain switched on. :) Coding in C takes more work because the compiler does not try to protect you from every possible mistake.

But in case of main function if return 1; or other would have some meaningful sense, but return 0; has no sense.

A return value of 0 from main means success. Unless you compile with the std=c99 switch in gcc, omitting the return statement invokes undefined behavior because main has to return an int. If you do not explicitly return a value, the value that gets returned is what we call indeterminate. The value cannot be predicted and the resulting behavior of the calling process in turn cannot be predicted.

If you compile with std=c99, you can omit the return statement because C99 implicitly returns 0 if execution falls off the end of main without an explicit return statement. Otherwise, return 0; is a very good idea. If it still makes no sense to you, try return EXIT_SUCCESS; and include <stdlib.h>. That might look like more work is being done. ;)

Salem commented: Wise words indeed, there is no safety netting. +36
Tom Gunn 1,164 Practically a Master Poster

Why does the calling function does not reflect the change done in the called function? despite the fact that I pass the variable via pointer.

Passing by pointer only means that the pointed to object can be changed. If you want to repoint the pointer to another address, it has to be passed by pointer too because pointers are also passed by value:

#include <iostream>
using namespace std;

void foonochange(int *x) {
	int *y = new int(999);
	x = y;
}

void foochange(int **x) {
	int *y = new int(999);
	*x = y;
}

int main(void) {	
	int *x = new int(1);

	foonochange(x);
	cout << *x << endl;

	foochange(&x);
	cout << *x << endl;

	cin.get();
	return 0;
}

But this is C++, and C++ has pass by reference. You can pass a reference to the pointer and not worry about adding another explicit level of indirection:

#include <iostream>
using namespace std;

void foonochange(int *x) {
	int *y = new int(999);
	x = y;
}

void foochange(int*& x) {
	int *y = new int(999);
	x = y;
}

int main(void) {	
	int *x = new int(1);

	foonochange(x);
	cout << *x << endl;

	foochange(x);
	cout << *x << endl;

	cin.get();
	return 0;
}
Tom Gunn 1,164 Practically a Master Poster

If your goal is neat and tidy code, you should be abstracting the records into a struct and using functions to do the dirty work:

typedef struct StudentScore
{
    char name[SIZE];
    int biology,
        chemistry;
}
StudentScore;
int GetScoreRecord(FILE* ifs, StudentScore* score)
{
    return fscanf(ifs, "%s %d %d", 
                  score->name, 
                  &score->biology, 
                  &score->chemistry) == 3;
}
while (GetScoreRecord(input, &score))
{
    /* ... */
}
Tom Gunn 1,164 Practically a Master Poster

Please stop spamming the forum with questions that can be answered using a web search or any reference book on C.

Tom Gunn 1,164 Practically a Master Poster

C does not have pass by reference, but you can fake it by passing pointers and using indirection to get to the original object:

#include <stdio.h>

void nochangex(int x)
{
    x = 123;
}

void changex(int* x)
{
    *x = 123;
}

int main()
{
    int x = 0;

    printf("before nochangex %d\n", x);
    nochangex(x);
    printf("after nochangex %d\n", x);

    printf("before changex %d\n", x);
    changex(&x);
    printf("after changex %d\n", x);

    return 0;
}

Pointers are also passed by value, so just like x, if you want to change a pointer, you need to pass a pointer to that pointer:

#include <stdio.h>

static int global = 123;

void nochangep(int *p)
{
    p = &global;
}

void changep(int** p)
{
    *p = &global;
}

int main()
{
    int local = 0;
    int* p = &local;

    printf("before nochangep %d\n", *p);
    nochangep(p);
    printf("after nochangep %d\n", *p);

    printf("before changep %d\n", *p);
    changep(&p);
    printf("after changep %d\n", *p);

    return 0;
}

The reason your print_list() function fails is because in main(), the list pointer is still uninitialized even after calling create_list(). Any changes made in create_list() are made on a copy of the pointer from main(), so the pointer in main() is unchanged. You can prove this by making a quick change to main():

int main(int argc, char** argv)
{
    struct A* list = NULL;
    create_list(list);
    if (!list) printf("list is null!\n");
    else
    {
        print_list(list);
        free_list(list);
    }
    return 0;
}
Tom Gunn 1,164 Practically a Master Poster
main(int ac, char *argv[])

Even when you do not specify a return type, main returns int, but your main does not have a return value. If you do not return a value from main, a junk value is returned to the OS. Also, C99 does not support implicit int anymore, so you should be typing it explicitly to futureproof your code.

if(ac>1)
    {
          printf("Invalid number of arguments /n");
          exit(1);
    }

The test is backwards. :) If ac is greater than 1, it means there is an argument available.

else
    {
        int newpid;
        newpid=atoi(argv);
    }

newpid is declared in the else block, so it does not exist outside of that block. Whatever you do with newpid, it will go away when execution gets to the end curly brace for the else block. Also, argv is an array, so you need to specify which item in the array you want to convert to an int.

This code should help you get started. It is always a good idea to start with something small and test that it works before adding more complexity. Like a program to print the arguments and make sure you got that right before trying to spawn processes which is harder to debug:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int isInt(char const* p);

int main(int argc, char *argv[])
{
    int nProcesses = 0;
    int x;

    if (argc < 2)
    {
        fputs("usage: $prog {number of processes}\n", stderr);
        exit(EXIT_FAILURE);
    }

    if (!isInt(argv[1]))
    {
        fputs("integer argument expected\n", …
MentallyIll5150 commented: Thanks! +1
iamthwee commented: Good explanation and carefully thought out. +22
Tom Gunn 1,164 Practically a Master Poster

Why ... T1 &var=T1(), T2 &var=T2()?

and not simply

.. T1 &var, T2 &var

does the appendix =T1() has an additional meaning?

If you have a function that takes 4 parameters, you have to provide all parameters when calling it:

#include <iostream>

void function(int a, int b, int c, int d)
{
    std::cout << a << '\t'
              << b << '\t'
              << c << '\t'
              << d << '\n';
}

int main()
{
    function();           // error
    function(1);          // error
    function(1, 2);       // error
    function(1, 2, 3);    // error
    function(1, 2, 3, 4); // ok
}

The additional code I added was default values for the parameters. With default values, if you do not provide enough arguments, the default values are used and the function looks like it is overloaded:

#include <iostream>

void function(int a=0, int b=0, int c=0, int d=0)
{
    std::cout << a << '\t'
              << b << '\t'
              << c << '\t'
              << d << '\n';
}

int main()
{
    function();           // ok
    function(1);          // ok
    function(1, 2);       // ok
    function(1, 2, 3);    // ok
    function(1, 2, 3, 4); // ok
}

For a template argument called T, T() is the default value for that type. So for T==int, T() is 0. For T==string, T() is "". The template I wrote says that all of the parameters with a template argument type have a default value of the template argument type. :)

Tom Gunn 1,164 Practically a Master Poster

I mentioned printf() and how the iostream library fixes the type safety problem. That is a good place to start, but it means that you will not be able to use format strings in the same way, and there will be lots of overloading for different types.

To be honest, I am not sure how I would solve this problem. Maybe after a day or two letting it simmer, I can give you a better answer. :)

Tom Gunn 1,164 Practically a Master Poster

Thus a void pointer seemed to be the most powerful way.

Void pointers are powerful, but you lose any kind of type checking when you use them. That is the trade off. This message system has the same problem that printf() does, and which the iostream library overcomes. There is no way to check that the argument types match the format string.

The only thing I can think of without overhauling the entire system to be type safe is a master template:

template <class T1, class T2, class T3, 
          class T4, class T5, class T6>
void gFont::AddTest (int passedPosition, 
                     std::string passedString, 
                     T1 &var1=T1(), T2 &var2=T2(), T3 &var3=T3(),
                     T4 &var4=T4(), T5 &var5=T5(), T6 &var6=T6())

With the default values you can pass fewer than the maximum and just ignore the ones that are not in the format string. As long as the master template supports as many parameters as you pass, it will work.

Tom Gunn 1,164 Practically a Master Poster

Is it a general rule that the level of indirection on both sides of the = operator should be equivlant?

The general rules is that both sides of the = operator need to have the same type or a compatible enough type for an implicit conversion. Different levels of indirection are neither the same type nor compatible.

Tom Gunn 1,164 Practically a Master Poster

is there a way to change a member void pointer to an int pointer?

The member is a void pointer, that will not change unless you change the type in your class definition. The only way to turn the void pointer into an int pointer is to cast it when you need an int pointer, as in my example.

Also, is there a way to know the type of passed pointer? Let's say I pass an int* to Do(void* p). How can I figure out that int* was passed?

You can do it, but not with void pointers unless you want to write a smart pointer class that knows the type. Using templates and RTTI will give you enough information to figure out what type of pointer was passed:

#include <iostream>
#include <typeinfo>
#include <string>

template <typename T>
void function(T* p)
{
    if (typeid(T) != typeid(int))
    {
        std::string actualType = typeid(T).name();
        throw std::invalid_argument(actualType + "* does not match int*");
    }

    std::cout << *(int*)p << '\n';
}

int main() try
{
    int ivalue = 123;
    double dvalue = 123;
    int *pi = &ivalue;
    double *pd = &dvalue;

    function(pi);
    function(pd);
}
catch (std::exception const& e)
{
    std::cerr << e.what() << '\n';
}

But I think you are probably doing something unnecessary. The actual type of a void pointer should be well known or not needed. If you need it, your design needs work. So what are you writing that needs this kind of type check?

Tom Gunn 1,164 Practically a Master Poster

Cast the void pointer when you want to use it as an int pointer, not when you want to store it as a void pointer:

#include <iostream>

class A;
class B;

class A
    {
    public:
        A():      pVar(0){};
        
        void*     pVar;
    };

class B
    {
    public:
        B(){};
        void      Do(void *passedVar);
    };

void B::Do(void *passedVar)
    {
    A* a = new A;
    a->pVar = passedVar;

    std::cout << *static_cast<int*>(a->pVar) << '\n'; 
    }

int main()
    {
    B* b = new B;
    int value = 123;
    int*cVar=&value;

    b->Do(cVar);
    }
Tom Gunn 1,164 Practically a Master Poster

Try this:

IDirectSound8* pDS8 = NULL;

HRESULT hr = DirectSoundCreate8(NULL, &pDS8, NULL);

And are you linking with the direct sound lib?

Tom Gunn 1,164 Practically a Master Poster

You may want to look at std classes.

vector<string> myStringArray

is way better than the clasical array

In C? ;)

Tom Gunn 1,164 Practically a Master Poster

cannot convert parameter 2 from 'LPDIRECTSOUND8' to 'LPDIRECTSOUND8 *'

This probably means that parameter 2 is an output parameter and needs to be a pointer:

HRESULT hr = DirectSoundCreate8(NULL,  &ppDS8, NULL);

I do not know much about the DirectSound API, so that is the best I can help without pretending I know by reading MSDN. ;)

Tom Gunn 1,164 Practically a Master Poster
#include <iostream>

void a_func(void (*func)())
{
    func(); // this should work
    (*func)(); // more explicit
}

void test()
{
    std::cout << "test\n";
}

int main()
{
    a_func(test); // this should work
    a_func(&test); // more explicit
}

When you have a function, you can do two things with it: call it or take its address. If you are not calling it, you are taking its address, which is why test and &test both evaluate to the address. You also do not need to dereference the pointer to call it, which is why func() and (*func)() both work. You can do crazy stuff like (*&*&*&******&func)(); too, but that should be reserved for obfuscated code contests. ;)

void* this_func = func;

Unfortunately, void pointers and function pointers are not compatible. Void pointers only work for object types, so you would need to do something like this:

void (*this_func)() = func;

Like Sky Diploma showed, a typedef makes the declaration easier:

typedef void (*pf_t)();
pf_t this_func = func;

But be careful because Sky Diploma's code should not compile. There are minor syntax errors that are not worth mentioning, but a real error is here:

func_int varname = &name;

Always be careful to match the level of indirection. &name is a pointer to func_int, not a func_int, so the level of indirection for the right hand side does not match the left hand side. The compiler should throw an error for this, and the fix is to remove the & …

Tom Gunn 1,164 Practically a Master Poster

I also have to implement [...]

Right, *you* have to. If you do not know where to start, say so. If you already have something that does not work, post it and somebody can tell you where you went wrong. Otherwise it looks like you are asking for someone to do your homework for you.

These links might help if you do not know where to start:
http://www.parashift.com/c++-faq-lite/ctors.html
http://www.parashift.com/c++-faq-lite/assignment-operators.html
http://www.parashift.com/c++-faq-lite/operator-overloading.html

Tom Gunn 1,164 Practically a Master Poster

readb has declared under public section but am unable to access that through the derived class object d.
d.readb();//is ambiguous

read() is ambiguous, readb() should not be. You created the Diamond Problem where the most derived class has two copies of the same base object. Virtual inheritance fixes this problem by forcing only a single copy of the shared base class.

I fixed other problems that kept your code from compiling on my newer compiler, so it may not compile for you until you change the header back to <iostream.h> and remove the using namespace std; line. The rest of the code should continue to work on an old compiler:

#include <iostream>

using namespace std;

class A
{
public:
    void read()
    {
        cout << "read\n";
    }
};

class B: virtual public A
{
public:
    void readb()
    {
        cout << "readb\n";
    }
};

class C: virtual public A
{
public:
    void readc()
    {
        cout << "readc\n";
    }
};

// B and C share an instance of A
class D: public B, public C
{
public:
    void readd()
    {
        cout << "readd\n";
    }
};

int main()
{
    D d;
    d.read();
    d.readb();
    d.readc();
    d.readd();
    return 0;
}
Tom Gunn 1,164 Practically a Master Poster

You know how to use 1D arrays, right? 2D arrays are 1D arrays where every item is an array. C has arrays of arrays instead of true multidimensional arrays:

int a[5] = {1,2,3,4,5};

[0] -> [1][2][3][4][5]

int b[3][2] = 
{
    {1, 2},
    {3, 4},
    {5, 6}
};

[0] -> [1][2]
[1] -> [3][4]
[2] -> [5][6]
#include <stdio.h>

#define ASIZE 5
#define BXSIZE 3
#define BYSIZE 2

int main()
{
    int a[ASIZE] = {1,2,3,4,5};
    int b[BXSIZE][BYSIZE] = 
    {
        {1, 2},
        {3, 4},
        {5, 6}
    };
    int x, y;

    for (x = 0; x < ASIZE; ++x)
    {
        printf("%d%s", a[x], x < ASIZE - 1 ? " " : "\n");
    }

    for (x = 0; x < BXSIZE; ++x)
    {
        for (y = 0; y < BYSIZE; ++y)
        {
            printf("%d%s", b[x][y], y < BYSIZE - 1 ? " " : "\n");
        }
    }

    return 0;
}

A string variable is a char array, right? So an array of strings is an array of char arrays, and instead of using name to get the string variable, you use name[x] . Everything else is the same:

#include <stdio.h>
#include <string.h>

#define NAME_CNT 5
#define NAME_LEN 20

int main()
{
    /* 5 names up to 19 chars each */
    char name[NAME_CNT][NAME_LEN];
    size_t x, y, n;

    printf("Enter %d names\n", NAME_CNT);

    for (x = 0; x < NAME_CNT; ++x)
    {
        printf("Name #%d: ", x + 1);
        fflush(stdout);

        if (!fgets(name[x], NAME_LEN, stdin)) break;

        /* trim any trailing line break */
        n = strlen(name[x]);
        if …
yellowSnow commented: An excellent and informative reply. +4
Nick Evan commented: seconded +24
Tom Gunn 1,164 Practically a Master Poster

The order of cin.clear() and cin.ignore() is backward. cin.ignore() is just as much a read as cin.get() , so if the stream is in an error state, nothing will be read. The code needs to clear first, then ignore:

if (!cin)
{
    name.clear();
    cin.clear();
    cin.ignore(256, '\n');
}

I also added '\n' to the call because the delimiter defaults to EOF. That turns cin.ignore() into a blocking read because it waits for up to 256 characters or EOF.

tux4life commented: Perfect! +19
Tom Gunn 1,164 Practically a Master Poster

Your inner loop does not account for the name being accepted and there is no way to break out of it without somehow signaling a character that has a value of 0. This will work better:

while (!name_accepted && cin.get(ch))

Otherwise the code works fine.

Tom Gunn 1,164 Practically a Master Poster

But what is he honestly going to do with it? Look at it, compile it, get his results. Then what?

I like to give examples because I think everyone learns better with code. If I have to post code that is too advanced because of unreasonable restrictions by you people, then he will just have to go the extra mile to learn from it.

I have already seen what happens when I try to give examples at the right level. Everybody attacks me for giving away code. If you want to be useful, show me how to post helpful code without everyone having a hissy fit. Otherwise your criticism is unconstructive will be ignored.

nav33n commented: Agree! +11
Tom Gunn 1,164 Practically a Master Poster

But how is that code supposed
to help the OP ( a beginner ) understand what he needs, when he most likely,
has no clue of what some of the code does.

It is not, obviously. If I gave an example that could be turned in as homework, I would get slammed by every net nanny on Daniweb for giving away code. Of course, now I get slammed for not being helpful enough. There is no winning this game. The only solution is not to post at all. :@

Anyway, I explained the algorithm as well as gave code. There is sufficient information for him to figure it out.

Tom Gunn 1,164 Practically a Master Poster

Static libraries are usually distributed as a *.h file and a *.lib file. Is this a third party library where you do not have the source? If so then there should be some compiled file along with the header that you can link to.

Tom Gunn 1,164 Practically a Master Poster

That error means those are either functions or objects that have been declared but not defined. A common cause is forgetting to give a body to one of your functions:

void function();

int main()
{
    function(); // error!
}

Another is including the headers for a library but forgetting to link to the library itself. Headers typically only contain declarations. I cannot tell you for sure what the problem is because I do not recognize those names.

Tom Gunn 1,164 Practically a Master Poster

Could I suppose this is the rules of c++?

Yes. The methods of a class can see everything in the class regardless of the access level. That is because a class can always see its own privatemost stuff. This is all at the class level, not the object level. When classes are instantiated into objects, the objects follow the rules of the class.

It is the same way with friends. When you declare a friend class or function, that class or function can see everything regardless of which object you give it.

Tom Gunn 1,164 Practically a Master Poster

I need to know how to calculate the standard deviation?

Do you know what the standard deviation is and how to calculate it on paper? The standard deviation of a set shows how the items in the set are dispersed. If the standard deviation is low, the items tend toward the mean, and if the standard deviation is high, the items are all over the place.

You calculate the standard deviation by finding the mean, then subtracting the mean and squaring the result for each item to create a new set. The square root of the average of the new set is the standard deviation:

// code intentionally advanced to deter cheaters
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
#include <cmath>

template <typename T>
struct SquareOfDiff:
    public std::binary_function<T, double, T>
{
    T operator()(T x, double mean) const
    {
        x -= (T)mean;
        return x *= x;
    }
};

int main()
{
    std::vector<double> set;
    double mean;

    std::cout << "Distriution set: ";
    std::copy(
        std::istream_iterator<double>(std::cin),
        std::istream_iterator<double>(),
        std::back_inserter(set));

    mean = std::accumulate(set.begin(), set.end(), 0.0) / set.size();
    std::transform(
        set.begin(), set.end(), 
        set.begin(), std::bind2nd(SquareOfDiff<double>(), mean));
    mean = std::accumulate(set.begin(), set.end(), 0.0) / set.size();

    std::cout << "Standard deviation: " << sqrt(mean) << '\n';
}
iamthwee commented: Doesn't really help the OP considering his level. -4
Salem commented: Works for me, the OP has already lost anyway. +36
Tom Gunn 1,164 Practically a Master Poster

Please post more code, or an example that has the same problem. Something is wrong, but playing 20 questions will take a while. ;)

Tom Gunn 1,164 Practically a Master Poster

Static methods are called like this:

UIClass::GetStatic( IDC_OUTPUT )->SetText( wszOutput );

Replace UIClass with the name of the class for g_SampleUI.

Tom Gunn 1,164 Practically a Master Poster

If you are trying to initialize the array inside a class definition, that will not work. To initialize like that the array needs to be global, local to a namespace, or local to a function.

Tom Gunn 1,164 Practically a Master Poster

Your class only allows one name, you need to define an array of 3 names and then use it as an array in the methods:

class A
{
    int a[3];
    char name[3][20];
public:
    void read();
    void display();
};
void A::read()
{
    cout<<"enter rno name";
    for(int i=0;i<3;i++)
    {
        cin>>a[i];
        cin>>name[i];
    }
}
void A::display()
{
    for(int i=0;i<3;i++)
        cout<<a[i]<<name[i];
}
#include<iostream.h>

<iostream.h> is an old header that new compilers might not recognize. This is a real problem. My compiler barfs on your code because <iostream.h> is not supported anymore. If you use an old compiler that does not support the new headers, you are selling yourself short and cannot learn the best parts of C++. If you use a compiler that supports both old and new headers, start using the new ones because the old ones are being phased out at warp speed. ;)

char name[10];

This is where the new C++ library can help you. Instead of using arrays of char for strings, you can use the C++ string class and working with strings gets a whole lot easier when you start to get into dynamic sizing and common string operations:

#include <iostream>
#include <string>

class A
{
    int a[3];
    std::string name[3];
public:
    void read();
    void display();
};

void A::read()
{
    for (int i = 0; i < 3; i++)
    {
        std::cout << "enter rno name: ";
        std::cin >> a[i] >> name[i];
    }
}

void A::display()
{
    for (int i = 0; i < 3; i++) …
Tom Gunn 1,164 Practically a Master Poster

This example is intentionally weak, because you might be a student looking for a free ride on homework. But it shows that what you asked for is possible.

#include <algorithm>
#include <iostream>
#include <list>

int main()
{
    typedef std::list<int> list_t;
    typedef list_t::iterator iter_t;
    typedef list_t::const_iterator citer_t;

    list_t list;

    for (int x = 0; x < 10; ++x) list.push_back(x);

    citer_t x = list.begin();
    list_t::size_type k = 0;

    // get a range [2..5)
    while (x != list.end() && k < 2) ++x, ++k;
    while (x != list.end() && k < 5)
    {
        std::cout << *x++ << ' ';
        ++k;
    }

    std::cout.put('\n');

    int a[10];

    // assign to variables?
    for (x = list.begin(), k = 0; x != list.end(); ++x) a[k++] = *x;
    for (k = 0; k < list.size(); ++k) std::cout << a[k] << ' ';

    std::cout.put('\n');
}
Tom Gunn 1,164 Practically a Master Poster

Correctly in that you get two true results? Do you get the same result if you print everything just before the if statement?

Tom Gunn 1,164 Practically a Master Poster

File:f:\dd\vctools\crt_bld\self_x86\crt\src\fgetc.c
Expression: (stream !=NULL)

This is an easy one. The stream you passed to fgetc is NULL. It means fopen returned NULL because the file could not be opened for some reason. Check the result before using it:

FILE* fp = fopen(file, mode);

if (!fp)
{
    perror("fopen");
    exit(EXIT_FAILURE);
}

Replace exit() with whatever recovery method you want. :)

Tom Gunn 1,164 Practically a Master Poster

Did you print the result of the expression to see what happens? :)

cout << hex << header[0] << '\t' 
     << boolalpha << (header[0] == 0xFF) << '\n';
cout << hex << header[1] << '\t'
     << hex << (header[1] & 0xE0) << '\t'
     << boolalpha << ((header[1] & 0xE0) == 0xE0) << '\n';
Tom Gunn 1,164 Practically a Master Poster

Is not Turbo C a nd Turbo C++ very outdated?

Yes, but so is DOS. He wants to write code for DOS 6.x, so Turbo C++ is not as bad a choice as it would be if he were targeting a modern OS.

Tom Gunn 1,164 Practically a Master Poster

Add a cout statement to print the bytes right after reading them. Debuggers sometimes lie, and it could be telling you they are 0x00 when they really are not.

Tom Gunn 1,164 Practically a Master Poster

Old C meaning the latest standard will not allow it. If you compile as C89, the implicit int works, but if you compile as C99, it will throw an error. gcc supports both standards, so it depends on your compiler settings.

tux4life commented: Clean, sweet, and solid! +18
Tom Gunn 1,164 Practically a Master Poster

Check the header variable between the file.get() and f.setHeader(). Are the bytes the right value and in the right order? Then check it again after f.setHeader() is called and make sure that the bytes have not changed.

Tom Gunn 1,164 Practically a Master Poster

1) to get the range of elements such as ..
A list of 10 elements beginning from value 1 to 10. I would like to get the range from element 3 to element 5 and add them to another list. Is it possible?

Yes, it is possible. A list is bidirectional. You can go forward and backward, but there is no random access. Getting a range from x to y is fine, but if x is far into the list it might not be as efficient as with a vector.

2) Within the list, can i get all the elements and assign to variables respectively?

Probably, unless you mean something different from what I understand. :)

Tom Gunn 1,164 Practically a Master Poster

That example was just to show that the opening curly brace had a corresponding closing curly brace. :) Your error is coming from the class definition not having a closing curly brace and semicolon:

#include <iostream>

using namespace std;

class cat
{
public:
    unsigned short int age;
public:
    void meow()
    {
        cout << "MY AGE IS " << age << endl;
    }
}; // add this line
Tom Gunn 1,164 Practically a Master Poster

Opening curly braces need to be matched with closing curly braces. The braces keep the stuff inside from falling out and choking the compiler. :D

// class definition
class MyClass
{
public:
    // public stuff
private:
    // private stuff
}; // close the definition
// method/function definition
void MyFunction()
{
    // stuff to do
} // close the definition
Tom Gunn 1,164 Practically a Master Poster

Can you give an example of a sequence of bytes that should pass the test but does not?

Tom Gunn 1,164 Practically a Master Poster

To cut from the right, you can take a substring of a smaller length:

string q = s.Substring(0, s.Length - 2) + somethingElse; // replace "mv" with something else
Tom Gunn 1,164 Practically a Master Poster

this thread was not put here to make anyone mad

Wow maybe i should stop this thread befor everyone starts to hate me.

I do not see where anyone got mad. Challenging your idea is not the same as hating you. ;)

Tom Gunn 1,164 Practically a Master Poster

But the purpose of using virtual inheritance is to avoid ambiguity while inheriting from multiple base classes

Right. Virtual inheritance is kind of like inheriting a reference to a class instead of the class itself. All child classes use the reference instead of a separate copy and there is no ambiguity because there are no copies, just the original.

Tom Gunn 1,164 Practically a Master Poster

I would like to know if functions with same names in different classes be inherited all the time or will only one instance of the function be included in the derived class?

Everything that can be inherited will be inherited, even if it causes an ambiguity.

Would inheriting D and F virtually for class H solve the ambiguity?

No, the ambiguity is in D and F, not H. Both D and F have an object of B, so the only way to fix that ambiguity is to virtually inherit B when deriving D and F.

Tom Gunn 1,164 Practically a Master Poster

I do not understand the question. In my example the last two loops do not use the array at all for accessing values. In the third loop the array is only used to get a pointer to the end for stopping the loop. Post the code you are trying to write, maybe that will help me understand what you want.