Narue 5,707 Bad Cop Team Colleague

>bool isPalindrome(string);
I'm of the opinion that parameter names are important even in your prototypes. Also note that the type should be exact. Presently you have a type mismatch because the declaration claims a string object and the definition claims a reference to a const string object. Those are different types.

>in.open(argv[1]);
This can be done with the constructor, and in general it's better to initialize at the point of definition as well as define your variables shortly before they're used. This tends to make code easier to read as you don't have a slew of variables at the top of the function and the need to guess where they're used.

argv may not be large enough as well, you should check the value of argc to verify that everything is kosher for opening the file.

>if(in.fail())
Not wrong, per se, but it's more conventional to say if (!in) .

>cout<<"File not opening!" << endl;
cerr should be preferred for error messages. You can also call perror (in <cstdio>) to display a friendly string representing the error that actually occurred. It's not strictly portable, but I have yet to see it not work. ;)

>system("pause");
This isn't a portable construct, and it's potentially a security risk. The pause program may not exist (which is why it's not portable), and the pause program could be added or replaced with a malicious program. Use the system function with great care, or not …

iamthwee commented: You like the' construct'... watching too much of the matrix. +13
Narue 5,707 Bad Cop Team Colleague

can you please tell me short and best answer so that i can understand it more clearly...

Compilers are not required to support anything but the following two definitions of main (equivalent definitions are allowed though):

int main()
{
    ...
}
int main(int argc, char *argv[])
{
    ...
}

The problem with void main is portability. Your code might be just peachy on one compiler, but invoke undefined behavior on another. There's no reason to introduce that kind of risk on a trivial feature that doesn't do anything or save you any effort. In fact, in standard C++, void main actually adds a single keystroke because you can always omit the return statement.

my teacher asked me the reason that why it is standard to use int before main?

Now that's a good question. Usually the question is "why do we have to return int", and the answer is "because the standard says so". But why the standard says so is a more interesting matter of history. In terms of C++, Stroustrup's desire to maintain as much compatibility with C as possible had a huge influence. The return value and multiple version rules of C were kept for C++. So for C++ the answer of "why" is simply, "because that's how C did it at the time". Now why did C do it that way?

Way back when, C was designed for and ran on UNIX. UNIX had a runtime startup that called main with two …

JasonHippy commented: Succinctly, comprehensively and very patiently put! +4
jonsca commented: This is getting a bookmark (you've doubtlessly said it before, I know) +6
katmai539 commented: Well written complete answer. +1
Ancient Dragon commented: When are you going to write your own book :) +35
Duki commented: I agree with AD. If you wrote a book, I would buy imediately. I sometimes read your posts just to learn something new. Thank you. +7
mike_2000_17 commented: very interesting!! +1
myk45 commented: Nice explanation +1
yash.newcomer commented: Thank you +0
Narue 5,707 Bad Cop Team Colleague

Then you're not opening the path you think you're opening. Consider the string: "D:\TC\myprog\readit.txt". Do you recall that escape characters start with a backslash? If you want a literal backslash, double them up: "D:\\TC\\myprog\\readit.txt". Alternatively, a forward slash also works: "D:/TC/myprog/readit.txt"

Narue 5,707 Bad Cop Team Colleague

If the file doesn't open, you can use perror to print the reason code:

if (fp == NULL)
    perror(NULL);
Narue 5,707 Bad Cop Team Colleague

addinf and address are both pointers to structures, so you'd need to dereference the pointer before accessing members:

(*(*stud.addinf).address).housenumb = 123;

Alternatively, the arrow operator does this for you in a much more convenient manner:

stud.addinf->address->housenumb = 123;

Note that those pointers must point to something first. Pointers aren't magic.

vedro-compota commented: ++++ +1
Narue 5,707 Bad Cop Team Colleague

While turbo is outdated, its simplicity gives confidence to beginners, to start thinking like a programmer.

I fail to see how using a limited and ancient compiler (which tends to cause no end of unnecessary problems and questions) is justified by a minor confidence boost from a simple IDE. Further, there are modern IDEs that are simple, so you're doing nothing but encouraging people to be so stuck in the past as to make life vastly harder when they try to catch up.

Narue 5,707 Bad Cop Team Colleague

This is your code with better formatting:

System::Void playBtn_Click(System::Object^  sender, System::EventArgs^  e) 
{
    // Tian: for this example, I restrict the selection and playing of one track only. You can make it more flexible
    if(this->listView1->CheckedItems->Count != 1) {
        MessageBox::Show("Please check one of tracks from the list below to play!");
        return;

        //axWindowsMediaPlayer1->Ctlcontrols->next();
        int random;
        Random^ rand;
        rand = gcnew Random();
        int count = axWindowsMediaPlayer1->mediaCollection->getAll()->count;
        random = rand->Next(count);
        axWindowsMediaPlayer1->currentMedia = axWindowsMediaPlayer1->mediaCollection->getAll()->Item[random];
        axWindowsMediaPlayer1->Ctlcontrols->play();
    }
}

// the actual music file and its path is kept in the second subItem (of each track)
String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;
Narue 5,707 Bad Cop Team Colleague

This particular error is within a play button command.

No, it's not. Count your braces and you'll see that filePath is defined outside of playBtn_Click. Or you could properly format your code to begin with and this would be immediately obvious.

Narue 5,707 Bad Cop Team Colleague

The file names are irrelevant. What is you class called?

Narue 5,707 Bad Cop Team Colleague

You didn't post enough code for me to be sure, but from the error I'd guess filePath is a data member and you're doing something like this:

ref class Form1 {
    String^ filePath = this->listView1->CheckedItems[0]->SubItems[2]->Text;

    // ...
};

C++ doesn't work like that though, you want to do non-default initialization from the constructor in most cases:

ref class Form1 {
    String^ filePath;

    // ...
public:
    Form1()
        : filePath("some value")
    {}

    // ...
};

Though since you're trying to use the Text property of a control, you'll likely need to wait until after the controls have been fully initialized. A good time to do this is in the form's Load event:

void Form1_Load(Object^ sender, EventArgs^ e)
{
    filePath = listView1->CheckedItems[0]->SubItems[2]->Text;
}
Narue 5,707 Bad Cop Team Colleague

I don't believe the for each (idiom?) exists in C++/CLI.

It does:

#include <iostream>
#include <vector>

int main()
{
    std::vector<int> v;

    for (int i = 0; i < 10; i++)
        v.push_back(i);

    // C++/CLI foreach
    for each (int x in v)
        std::cout<< x <<'\n';
}
jonsca commented: I believe! I believe! Thanks for the clarification! +6
Narue 5,707 Bad Cop Team Colleague

Sorry, it seems that when you said you were "fairly skilled" in C, C++, Java, and Javascript, I mistakenly assumed you were nearing a level of competence necessary for entering the workforce.

where would I start with a central database

Start by getting a database going. Freely available options include MySQL and SQL Server Express. You can use a library such as SQLAPI++ to access the database with C++. However, I suspect you'll also need to do some studying on writing SQL queries.

I take it that this is possible in c++

Very little is not possible in C++, and those things are usually so low level as to require scratching bare metal with assembly.

Could you explain a web service to me?

Wikipedia is handy.

Narue 5,707 Bad Cop Team Colleague

Turbo C is a 16-bit compiler, which essentially means that the actual range of int is [32,767, -32,768] (16 bits, two's complement). It simply can't handle 800000, but long can. The fix in your case is to change your code to use long instead of int.

As a side note, for maximum portability it's best to use int only when the values are guaranteed to be within the range of [32,767, -32,767] (ie. 16 bits). For anything beyond that, use long (up to a range of 32 bits). The reason is that these are the minimum ranges specified in the C standard. You're absolutely guaranteed to have at least that much, but any more is implementation-dependent.

Narue 5,707 Bad Cop Team Colleague

Obviously, defining it within the class definition would be ideal, but would something like this still work?

Sure, either way the definition is in the header and ultimately makes it into any translation unit where Sample is used. Which is better depends on the length of GetPrivateVal and personal preference.

Fbody commented: :) +5
Narue 5,707 Bad Cop Team Colleague

Assuming your ints are 32-bit, FFFFFF01 exceeds INT_MAX. strtol should correctly return INT_MAX because the value passed in is out of range. While I'm sure you expected strtol to take a value with the sign bit set and produce a negative value, that's not how it works. The values are expected to be in range, and any sign is interpreted with a leading + or -.

Narue 5,707 Bad Cop Team Colleague

What kind of hacker? You have the traditional hackers who treat learning new things almost as a religion, and the more recent hackers who break into and defend systems. Are you talking about the subculture as a whole, or do you want individual anecdotes? I can personally vouch that there's great variance in background amongst individual hackers.

Narue 5,707 Bad Cop Team Colleague

According to the book, it said "This is not guaranteed to remove the third element, even though that was intended. In most real-world STL implementations, it erases both the third and the sixth elements."

Beware lack of context. Your quote is actually quite wrong when taken out of context, but the book is using that as an example for an implementation that implements remove_if in terms of find_if and remove_copy_if.

Perhaps it would help if I gave you an alternative implementation of remove_if that matches the description in your book:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

namespace jsw {
    template <typename FwdIt, typename Pred>
    FwdIt remove_if(FwdIt first, FwdIt last, Pred pred)
    {
        first = std::find_if(first, last, pred);

        if (first == last)
            return first;

        // operator+ is not defined for forward iterators,
        // so operator++ on a dummy is necessary
        FwdIt src = first;

        return std::remove_copy_if(++src, last, first, pred);
    }
}

class FlagNth {
public:
    FlagNth( size_t n ) : current_(0), n_(n) {}

    template<typename T>
    bool operator()( const T& ) {return ++current_ == n_; }
private:
    size_t current_, n_;
};

int main()
{
    int init[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> v(init, init + 10);

    copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
    cout<<'\n';

    vector<int>::iterator end = v.erase(jsw::remove_if(v.begin(), v.end(), FlagNth(3)));

    copy(v.begin(), end, ostream_iterator<int>(cout, " "));
    cout<<'\n';
}

This example will fail as described because the predicate is being copied to both find_if and remove_copy_if. Each of their versions of n_ will …

Narue 5,707 Bad Cop Team Colleague

'Nuff said.

Narue 5,707 Bad Cop Team Colleague

Is it mandatory to use operator= overloading every time i write a copy constructor?

Unless you're going to make operator= private, it's a good idea to include it as well as a copy constructor and a destructor. Because if you need a copy constructor, more often than not you need to deal with assignments and destruction as well (the so called "Big Three"). The defaults typically aren't sufficient if any one of the big three are needed.

Narue 5,707 Bad Cop Team Colleague

This is an example of using a binary index file to speed up random access of lines in a file. The file is indexed one time, where the position of the start of each line is stored in an index file. Subsequent requests for a get the position from the index file and seek directly to it.

Included is the usual naive brute force search for lines to compare performance.

Ancient Dragon commented: Excellent :) +35
Clinton Portis commented: good code snippet... learned a few things. still trying to figure some things out. +6
Narue 5,707 Bad Cop Team Colleague
Why????

It might make more sense if you convert to a while loop:

i = 1;

while (i <= 20)
{
    b = i * 30;
    printf("b é uguale a: %d = %d * 30\n\n",b, i);
    ++i;
}

i is always incremented after the body of the loop runs, and when i becomes 21 to fails the condition. So after the loop, i retains the value that failed the condition (ie. 21).

kvprajapati commented: Happy new year ma'am :) +11
Narue 5,707 Bad Cop Team Colleague

123 % 10 is 3.
123 % 100 is 23
23 / 10 is 2.
123 / 100 is 1.

Extrapolate an algorithm from that.

Narue 5,707 Bad Cop Team Colleague

Do it your damn self. If you have a specific problem with your code, we'll help, but don't expect anyone to do everything for you.

Narue 5,707 Bad Cop Team Colleague
^                         // Match the beginning of a string
    \(?                   // Match a literal '(' (zero or one)
    (?<NPA>               // Create a capture group named NPA
        [2-9]             // Match one digit in the range of [2-9]
        \d{2}             // Match two digits
    )                     // End the NPA capture group
    (\)?)                 // Match a literal ')' (zero or one)
    (-|.|\s)?             // Match zero or one of '-', '.', or a whitespace character
    (?<NXX3>              // Create a capture group named NXX3
        [1-9]             // Match one digit in the range of [1-9]
        \d{2}             // Match two digits
    )                     // End the NXX3 capture group
    (-|.|\s)?             // Match zero or one of '-', '.', or a whitespace character
    (?<NXX4>              // Create a capture group named NXX4
        \d{4}             // Match four digits
    )                     // End the NXX4 capture group
$                         // Match the end of a string

NPA (Number Plan Areas) is the area code. Since surrounding parens are optional, they're not included in the capture group (which you would use to extract them if doing more than just an existence match). The NXX (Central Office Exchange Code) groups represent the three digit and four digit parts of the local number. Like NPA, you can extract them independently due to the grouping.

kvprajapati commented: :) +11
Narue 5,707 Bad Cop Team Colleague

Start by getting a handle on socket programming: http://beej.us/guide/bgnet/

Narue 5,707 Bad Cop Team Colleague

Sure. Think of %[...] as %s where you define the recognized alphabet. Everything inside the brackets represents your custom alphabet, which in this case is {' ', '\t', '\n', '\r', '\v', '\f', ','} . The leading caret (^) alters the behavior to one of exclusion, so "%[^ \t\n\r\v\f,]" means read characters until one of the characters in the brackets is detected. Without the caret, it means that only those characters will be read, and every other character will be used as a delimiter.

Here are two common examples of scan set usage:

#include <stdio.h>

int main(void)
{
    char buf[BUFSIZ];
    int ch;

    /* Only accept digits */
    if (scanf("%[0123456789]", buf) == 1)
        printf("Successful read of the number '%s'\n", buf);

    /* Clear out leftovers */
    while ((ch = getchar()) != '\n' && ch != EOF)
        ;

    /* Read a full line */
    if (scanf("%[^\n]", buf) == 1)
        printf("Read a full line: '%s'\n", buf);

    return 0;
}
Narue 5,707 Bad Cop Team Colleague

For starters, you're not defining boundaries on the string, so you'll get false positives for an embedded match. Here's one from my personal library of regular expressions, it more or less rolls your two patterns up into one (but notice the boundary checks):

@"^\(?(?<NPA>[2-9]\d{2})(\)?)(-|.|\s)?(?<NXX3>[1-9]\d{2})(-|.|\s)?(?<NXX4>\d{4})$"
Narue 5,707 Bad Cop Team Colleague

Some suggestions?

You've got the right idea, just expand on it:

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

int main(int argc, char *argv[])
{
    if (argc > 1) {
        FILE *in = fopen(argv[1], "r");

        if (in != NULL) {
            char **lines = NULL;
            char line[BUFSIZ];
            size_t i, n = 0;

            while (fgets(line, sizeof line, in) != NULL) {
                char **save = realloc(lines, ++n * sizeof *lines);

                if (save == NULL) {
                    fprintf(stderr, "Error allocating memory for line #%d\n", n);
                    break;
                }

                lines = save;
                line[strcspn(line, "\n")] = '\0';
                lines[n - 1] = malloc(strlen(line) + 1);
                strcpy(lines[n - 1], line);
            }

            fclose(in);

            for (i = 0; i < n; i++)
                printf(">%s<\n", lines[i]);

            for (i = 0; i < n; i++)
                free(lines[i]);
            free(lines);
        }
    }

    return 0;
}
Mouche commented: Very helpful code snippet +5
Narue 5,707 Bad Cop Team Colleague

Is it ok to directly copy one object's content onto other ?

The problem is aliasing. For example, if any of your data members are pointers then an explicit copy constructor is required to make a deep copy of the object. Otherwise the pointers from two objects will point to the same block of memory:

#include <iostream>
#include <ostream>

class DynamicArray {
    int *_array; // Non-shallow type; suitable explicit copy constructor required
    int _size;
public:
    DynamicArray(int size): _size(size) { _array = new int[size]; }
    ~DynamicArray() { delete[] _array; }

    int& operator[](int i) { return _array[i]; }

    friend std::ostream& operator<<(std::ostream& out, const DynamicArray& da)
    {
        out<<'(';

        for (int i = 0; i < da._size; i++) {
            out<< da._array[i];

            if (i < da._size - 1)
                out<<',';
        }

        return out<<')';
    }
};

int main()
{
    DynamicArray arr1(5);

    for (int i = 0; i < 5; i++)
        arr1[i] = i;

    std::cout<< arr1 <<'\n';

    DynamicArray arr2 = arr1;

    for (int i = 0; i < 5; i++)
        arr2[i] = i + 10;

    std::cout<< arr1 <<'\n'<< arr2 <<'\n';
}

Notice how altering arr2 also changes the contents of arr1. That's because _array is an alias for the same block of memory. Both objects refer to the same underlying array. In this case a copy constructor is necessary to make a deep copy of the pointed to memory:

#include <iostream>
#include <ostream>

class DynamicArray {
    int *_array; // Non-shallow type; suitable explicit copy constructor required
    int _size;
public:
    DynamicArray(int size): _size(size) { _array = new …
Narue 5,707 Bad Cop Team Colleague

Well, technically, you shouldn't use arrays with a size determined through a variable.

Technically you can't. C++ doesn't presently support array sizes that aren't compile time constants. If it happens to work, it's due to a compiler extension, and thus not portable.

You passed your variables into ReadList correctly, but if you want to go by proper C++ naming conventions, you'll always use a lower-case first word or using underscores (so ReadList becomes readList or ReadList becomes read_list).

There are no "proper" naming conventions in C++, it's all across the board depending on the style guidelines one uses.It's not uncommon to match the style of the standard library as closely as possible, but that's tricky because then you run the risk of stomping all over the implementation's name space for internal or future identifiers.

The way you've currently set up you program, you have your function declarations placed firmly at the top of your file. That is not how to properly declare your functions. Use function prototypes at the top of the file and function declarations underneath the main function.

Both are perfectly valid. Just because defining functions ahead of main doesn't suit your style doesn't make it wrong.

If a user enters, for instance, 5 integers into the array, a lot of memory is wasted with 95 elements being unused.

Yes, that's generally how one handles variable length input with arrays: define an array with enough space for the upper limit of input and write off …

Narue 5,707 Bad Cop Team Colleague

Your constructor and class fields are nested inside Main. It should look like this:

class Student
{
    private int registrationNumber;
    private string name;
    private DateTime DateOfBirth;

    public Student()
    {
        Console.WriteLine("New Student created. Parameterless constructor called....");
    }

    public static void Main(string[] args)
    {
    }
}
Narue 5,707 Bad Cop Team Colleague

>I really need that code
Then write it. That's what I do when I really need code for something.

>I have a text file
>and I want to convert it vector or array

I'm sure you've used cin's >> operator to read integers from standard input. What you did was read a stream of text and convert it to int, though most of that work happened under the hood. You can do the same thing with your file:

#include <fstream>

int main()
{
    std::ifstream in("myfile");
    int x;

    if (in && in>> x)
        std::cout<< x <<" squared is "<< x * x <<'\n';
}
frogboy77 commented: sometimes i think you're almost human.(sometimes) +1
Narue 5,707 Bad Cop Team Colleague

>void main() is not legal C (under a hosted environment).
Incorrect. Since you seem to be a standard reader, look it up and you'll see "or in some other implementation-defined manner". This is an escape clause that allows implementations to support extended functionality, such as not requiring a return value (ie. void main) or additional parameters such as the common envp third parameter.

>Your options are (under C99):
>int main(int argc, char *argv[], char *envp[]);

Incorrect. C99 only defines explicitly a zero parameter version:

int main(void) { /* ... */ }

And a two parameter version:

int main(int argc, char *argv[]) { /* ... */ }

Your three parameter version falls under the escape clause, though it is mentioned as a common extension in annex J section 5 of C99.

Narue 5,707 Bad Cop Team Colleague

>but still in ur opinion, what technologies are best?
In my opinion, if "best" were so easily determined, there wouldn't be so many options.

>pls do suggest then what type of licensing is available
Google "open source licenses".

and its still not clear to me, if just by coding using open source APIs and languages,does it automatically make my code "freely ditributable" or does it happen only if i make the code distributable after licensing under GNU GPL?

Unless you're using a restrictive library that forces derivatives to be open source, you decide how the code is licensed. However, open source libraries that are used may have provisions that require open distribution of those parts. For example, you might be required to include full source for an open source library that you use along with the binaries of your otherwise closed source application.

Then is the reason that most people don't use Microsoft technologies for coding that they run on windows only?

No, portable code can be written on Windows. The Microsoft hate stems from politics. People don't like Microsoft as a corporation for various reasons, and they project that dislike onto Microsoft products. Sometimes the haters will find legitimate flaws in the products to attack, while at the same time ignoring similar flaws in their preferred alternative. It's both sad and humorous.

logically i'd believe its their APIs and stuff so they would charge atleast (demand a piece of the pie) something if …

Narue 5,707 Bad Cop Team Colleague

You realize that getchar is reading one character and returning the code value of that character, right? If you type "100", the values you get are likely to be 49, 48, and 48. Is this intended? Because it raises red flags when I read it.

Narue 5,707 Bad Cop Team Colleague

>Do me 1 favour...
Not only will I do you a favor, it'll be the single best favor you'll ever receive. I'm going to let you bomb this assignment. Then you'll learn that nobody is going to bail you out, that you should only rely on yourself, and you should expect the consequences of failure rather than a Hail Mary from people who couldn't give two shits about your marks.

You sat on your laurels for half a month (a timeframe that I commonly finish full projects in, much less synopses) and totally deserve to suffer because of it. Don't expect sympathy from any of us, because you're not likely to get it.

Jason Giggs commented: Now that's tough. :-) +1
Narue 5,707 Bad Cop Team Colleague

most of my friends advise me to go for open source development: use LAMP (linux,apache,mysql,php) combination if i ever develop a web app, or use OpenGL if developing desktop apps in c++ so that they can run on linux apart from windows only, or use java if ever getting thoughts of .net in my head.

Ignore them. A wise developer uses the best tool for the job; getting political only hurts the quality of software.

if i write some application in open source languages and environments, can i have the developer rights to it and use it commercially for my benefit?(provided i won't obviously use third party add ons)

Open source isn't synonymous with "non-commercial". Each license details it in a different way, but there's generally nothing stopping you from making a profit on the software provided the source remains available and royalty free.

is it correct that if i write desktop apps in vc++ or vb or c# or create pages in asp.net which are Microsoft's languages and technologies, then Microsoft is also the owner of that app because the technology used is Microsoft's , and i can't have any rights to it to use it for making money?

No, that's ridiculous.

Narue 5,707 Bad Cop Team Colleague

I think the appropriate question in this case is why do you want to invoke the destructor explicitly? It's called automatically at the right time except in some extreme and obscure situations (which you're not likely to encounter for a while).

Narue 5,707 Bad Cop Team Colleague

You can signal EOF with a keyboard combination. On Windows it's Ctrl+Z, and on POSIX systems it's Ctrl+D.

Narue 5,707 Bad Cop Team Colleague

>um ok...um ok...
You were expecting some sort of mystery of the universe? The difference is that signed types use half of the range for negative values. With unsigned types you have a wider positive range, and a guarantee of wrapping on overflow/underflow.

Narue 5,707 Bad Cop Team Colleague

The invocation would look something like this:

$ g++ file1.cpp file2.cpp file3.cpp
$ ./a.out

The header files need not be compiled as the preprocessor textually inserts them into your .cpp files. The resulting executable file is named a.out by default, but you can alter that with the -o switch:

$ g++ -o myprog file1.cpp file2.cpp file3.cpp
$ ./myprog
Narue 5,707 Bad Cop Team Colleague

Read characters until a newline or EOF is reached:

int ch;

do
    ch = getchar();
while (ch != '\n' && ch != EOF);

This is the only portable method, but it also has a downside of blocking for input if the stream is already empty when the loop starts. Unfortunately, there's no way to get around that without breaking portability.

vedro-compota commented: +++ +1
Narue 5,707 Bad Cop Team Colleague

very limited knowledge of this but this using ctime appears to give a rough time the code took to run.

double time=clock();
//program
cout<<clock()-time<<" ms"; or cout<<(clock()-time)/1000<<" seconds.";

This is more conventional:

#include <iostream>
#include <ctime>

int main()
{
    std::clock_t start = std::clock();

    // ...

    std::cout<< ((double)std::clock() - start) / CLOCKS_PER_SEC <<'\n';
}

While the assumption that clock_t will be meaningful when cast to double is not portable, I have yet to see an implementation where this construct fails. However, keep in mind that there's no portable way to achieve more than second granularity with timing in standard C++; any solution would require a non-portable library or assumption about the implementation.

If you're okay with second granularity, the difftime function can be used in a portable manner:

#include <iostream>
#include <ctime>

int main()
{
    std::time_t start = std::time(0);

    // ...

    std::cout<< std::difftime(std::time(0), start) <<'\n';
}

In all honesty, I use the non-portable construct when doing ad hoc timing simply because there's low risk of it failing, and it works well without using non-standard libraries. YMMV.

Narue 5,707 Bad Cop Team Colleague

>I've put the text back in the first post.
Excellent, now the thread is useful again. Though I don't think I'll be helping the OP anytime soon, after that wonderful display of community service.

>This is not an english classes or forum.
It's a matter of practicality. If you're too lazy to put any effort into asking questions, we assume you'll be equally lazy in interpreting and implementing the answers. Such wastes of time are avoided by the more clueful people around here, which means you'll likely be ignored by the most qualified helpers.

Narue 5,707 Bad Cop Team Colleague

>Is there any way I can prevent this copy?
No, not really. In calling operator<<, you've bound the temporary object to a reference, which basically invalidates it for further copy elimination.

>had I known that it would make copies all the time I would not have done it...
It's best to assume that at least one copy of an exception object will be made when throwing.

Narue 5,707 Bad Cop Team Colleague

>i knw everything but im using TURBO C++ version 3.0 it require these things
The problems you mentioned were only the tip of the iceberg and could easily be written off after learning you're forced to use Turbo C++. I'd go into more detail but you deleted your post's contents like a freaking moron. Thanks for destroying thread continuity.

Nick Evan commented: Homework kiddo's ...*sigh* +16
Narue 5,707 Bad Cop Team Colleague

Actually, endianness is irrelevant here. The logical behavior of shifting is the same regardless of how the underlying values are actually stored.

Fbody commented: good to know. :) +5
Narue 5,707 Bad Cop Team Colleague

>should i sort it??
It doesn't matter. I'd recommend keeping things simple until you have a working draft of the availability list.

>and i want to mark the record as deleted what should i use??
You don't need to mark the record as deleted. The presence of the search key/index in your avail_list serves that purpose.

Now for some advice. You're not going to learn jack until you take some chances, screw shit up, and get out of holes you dig for yourself. Your questions reek of fear. You're afraid of doing things the "wrong" way, or making mistakes, or having to start over from scratch because you made a poor decision in the beginning. But all of those are necessary to grow. The only way to get really good at this stuff is experience, and experience is nothing more than a mountain of mistakes. Don't expect people to hold your hand, because it's not going to happen, and it wouldn't help you in the long run anyway.

Narue 5,707 Bad Cop Team Colleague

>fillnumb will be =2
Why would it be? If fillnumb is 0, then that falls into your case 0, which sets fillnumb to 1. A break at the end of a case terminates the switch statement, so execution won't fall through to case 1.

Narue 5,707 Bad Cop Team Colleague

>int types are always initialized (to zero).
This misconception is why I asked for a more specific question. As an example, local variables are not automatically initialized, which means there's no way to check them without relying on compiler warnings/errors.

static void Main(string[] args)
{
    int i; // Not initialized (value type)
    string s; // Not initialized (reference type)

    // ...
}