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

what os and compiler ??? Looks like TurboC code, but can't be sure.

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

What is the problem? Just use ifstream's >> operator and it will skip all white space (spaces, tags, etc) between words.

>> How would i tell when the file ends

when the loop below exits

std::string word;
ifstream in("file.txt");
while( in >> word)
   cout << word << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here are a few google results you might want to read

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

c++ is not the best language for web sites -- use java instead. But if this is not for a web site then for gui I'd use wxWidgets or OpenGL. You could use pure win32 api but it would be more difficult.

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

>>cube = new CUBE;
You can't use the new operator on a vector. All you have to do is use its push_back() method to add a new item.

CUBE* cb = new CUBE;
cb->number = 0;
cb->changed = false;
cube.push_back(cb);

But you can make your life a little easier by adding a constructure to initialize the structure's variables.

And -- do not make it a vector of CUBE pointers. You could use pointers, but life is a little easier without them, especially since CUBE is such a small structure/class.

struct CUBE
{
    int number;
    bool changed;
    CUBE() { number = 0; changed = false; }
};

int _tmain(int argc, _TCHAR* argv[])
{
    vector<CUBE> cube;
    cube.resize(5);
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The stats in Control Panel seems to have a few problems.
>>Forum Threads Started: 3,668
I have not started that many threads! :icon_eek: According to the link "search all threads started by ...", I only started 190 threads.

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

Test thread. :)

>>Test thread :) Please ignore #1

Ok, I will :)

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

That is sick -- no wonder our kids are so screwed up today, and it seems to get worse every year. Hope someone puts a XXX rating on that game so that only adults can buy it. Or better yet, just ban it.

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

“security measures are inherently unreliable, can be trivially circumvented and will fail at high rates,"

I agree completely -- All you have to do to circumvent age questions is to lie about your age when asked. And porn sites have the same problem. Even asking something like SSN and looking it up in government database is useless since a minor could just simply enter a parent's SSN.

As for the proposed bill itself, I'd go along with it. We have enough government intrusion into our lives. People who have gambling problems need professional help, not government intervention.

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

Never fear -- Wal-Mart is always there to suck up the slack by failing Circuit City and Best Buy. Our store just doubled the size of the hi tech sales floor area.

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

This reminds me of a sci fi movie I saw years ago about everyone gets put to death on their 30th birthday because they are considered too old.

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

Let me get this straight -- google is indexing stuff that is already online and in public domain. So tell me, how is it going to get stuff not online or in classified/confidential databases? I fail to see how that can happen. How can google index something that is only available in paper form?

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

Of course the only place on Earth the 1st Amendment applies is within the borders of USA. Even American citizens have no such protection in other nations -- they have to obey host nation's laws just like everybody else in the host nation. "when in Rome to as the Romans do". And as has been said before, the 1st Amendment does not apply to non-government agencies such as corporations and businesses.

In the USA, business and corporations are similir to small dictatorships with some limitations of government rules and unions. Basically its Do as I tell you to do and if you don't like it then get the hell out! Of course what I tell you to do must be legal -- they can't tell you to murder somebody, or commit other crimes.

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

As you quoted, the First Amendment appllies to government agencies, not private industry. The owners of websites can prohibit any kind of speech they want to without restruction because there are no laws to stop them from doing that. When at work, on company time, using company-owned computers, the company has the right to monitor your every second on-the-job, monitor your use of the computer, dictate what you can and cannot do them them, and fire you for flagrent misuse. That's the way it is -- if you don't like it then get the f**k out of my company and work someplace else!

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

Who the hell came up with that XXX thing anyway? It's a good idea, but one that will never work -- like trying to make prostitution illegal :D :D

As for Marks/communism -- don't know and don't really care. They're pretty much irrelevent in today's world, unless of course you live in China or Cuba.

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

I suppose what this article is about is that graphic cards have become too efficient. Games that played quite well with older and somewhat slower models of the cards look like crap on these new cards. A couple months ago my monitor died so I bought a new flat-screen monitor and a new latest-and-greatest graphics card. My favorite game that played quite well on the older card is very jerky on the new one -- the character no longer runs smoothly across the screen. It might be that problem that this article is complaining about. I suspect game programmers are having a really difficult time keeping the game flowing as smoothly as they would like.

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

Well, benna, just exactly what does "low impact" mean, without using the words "low impact" ? If you can't define it then you probably don't know any more than CNN what that means. Microsoft, and other IT people too, are good at throwing around meaningless terms (gobbledegook)

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

I don't see how that bill will affect our energy consumption at all. I will still turn on the lights when the sun goes down no matter what time the clock says it is. And, if I were a farmer, the time change will not affect when I have to milk the cows, feed the hogs, or plow the fields.

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

I've been typing since before HS, in about 1958, and I've always used the original flat style keyboards. I hate those ergonomic split keyboards that benna loves -- I tried one at work once and couldn't type on it. The typewriters we learned to use in school had no letters on the keys either, but they were manual typewrites (not electric) and much simpler. I dobt the Dash keyboard pictured above will sell very well, except for maybe some schools.

Also, I don't even use the keyboard for games -- I use the mouse almost exclusively.

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

why should M$ care about sending security updates, or any other kind of updates, to pirated copies of the os? People dumb enough to install a pirated os diserve all the worms and viruses they can get! I have absolutely no sympathy for those people.

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

This is a simple example of how to delete a line from a text file. In order to do that you have to completely rewrite the file, leaving out the line(s) you want to delete. First open the input file, then open an output file (doesn't matter what filename you give it as long as its a legal file name for your computer system). After read/write loop finishes, close both files, delete the original (or rename it if you don't want to delete it) and rename the new temp file to the original filename.

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

>> A string can contain an '\0' before the actual end of the array
Yes it can, but that makes it a binary string, not an ascii string, and most string functions in C and C++ will not be able to deal with it.

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

excellent work. Only two suggestions:
1. fflush(stdin); -- fflush() is guarenteed to only work with output streams. Some compilers allow it for input streams, but that is compiler-specific and will not work on many compilers.

2. In the loop that gets keyboard input you should add a prompt to that the program does not appear to be hung up and doing nothing

for(index = 0;index < numNodes;index++)
	{
		printf("\rEnter item number %d ...", index);
		scanf("%d",&tempArray[index]);
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I previously posted an MS-Windows example program about how to recursively search folders and create a list of their filename. This program is similar in concept but is for linux. It c++ and uses std::string and std::vector classes to hold the strings. When the program encounters a directory it will recursively call itself to process that directory. All the directory names are placed into a vector of vectors.

One improvement that needs to be made if using this program is to maintain the names of the directories along with the vector or filenames.

Happy programming.:)

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

Here is a non-recursive version of the same.

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

char* _string_reverse( const char* src_string, char* dest_string )
{
	char *src_ptr = (char*)src_string + strlen(src_string)-1;
	char *dest_ptr = dest_string;
	
	while( src_ptr > src_string)
	{
		*dest_ptr++ = *src_ptr--;
	}
	*dest_ptr = 0;
	return dest_string;

}

int main()
{
	char inbuf[] = "Hello World";
	char outbuf[255] = {0};

	char *result = _string_reverse(inbuf,outbuf);
	printf("%s\n",result);

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

Very buggy program.

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

short program that will build a stl::list of directory names and all the files they contain. recursively calls itself when a new directory is encountered. This has been compiled with both VC++ 6.0 and Dev-Shed compiles on MS-Windows XP Pro. It will not work on *nix or probably MAC computers.

Illustrates simple use of std::list, std::vector, std::string, std::cin and std::cout. as well as intention of the program using _findfirsti64() and _findnexti64().

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

Here are some example how to use windows console api functions

http://www.codexxi.com/MyBlocks.html#atConsoleObj

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

the standard C library stat() is more portable to other operating systems.

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

Here is a c++ example. If all you want to do is display the files then you can easily convert it to C by just removing all the vector stuff and printing the filenames instead of storing them in a list of any kind.

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

I will give you lessons in english and then some assignments. And we will use Microsoft Visual C++ 6.0 as IDE!

That's a terrible idea:icon_eek: Why not use VC++ 2008 Express, which supports c++ a lot better than that old vc++ 6.0 compiler.

Otherwise, I applaud your efforts to teach c++. :) Do you have teaching experience? Do you plan to have different classes for people with different levels of experience (e.g. beginner, intermediate and advanced) ? Finally, do you expect your students to buy the teacher an apple ?

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

niek: Yes, that's a good description of what has to be done on *nix and Windows in order to successfully compile a program. I thought I wanted to try *nix for a little while -- I must have been temporarily insane.

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

[rant]
Its so damed confusing and difficult to use. I spent three days trying to install something on my Fedora 11 machine that would take me no more than about 10 minutes in Vista (or any other version of MS-Windows). As an example: wxWidgets. I couldn't even successfully compile their online Hello World tutorial because of uninstalled extra packages. Then after installing more packages using yum program, tried to compile Hello World and the g++ compiler couldn't find some include files. So I used find command to locate the header files and created a makefile to set -I flags for the include directories. That finally worked, but now I get trillions of undefined variables error messages. From this short experience it is no wonder that more *nix programmers don't commit suicide!

As for Vista: the same Hello World tutorial compiled without errors or warnings in about 15 minutes using VC++ 2008 Express. And not much more than that using Code::Blocks.
[/rant]

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

class variables do not have to be passed as parameters to class methods because the methods already have full access to them.

Post an example of why you think you need global variables.

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

Welcome to DaniWeb. Databases? Yes DaniWeb has several forums devoted to it -- they are listed under Web Development. Also questions about databases occasionally in the Software Development forums.

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

Thanks -- I finally got it installed. Someone at forums.fedoraforum.org told me to use this command: yum install gcc gcc-c++ make

tux4life commented: You naughty cross-poster ! :P +21
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler? what os? what kind of directives ? Do you mean pragmas or preprocessor directives or something else?

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

>>Is it possible to compile a single .cpp (not a project) in visual studio 2008
No.

>>Also will using visual studio cause problems executing code on a unix system?
If you mean run the *.exe on *linux, the answer is that it cannot. You will have to compiler it on the machine you want to run it on, in this case a *nix computer. The binaries are not compatible between the two operating systems.

>>It almost seems like a joke to have resource.h, stdafx.h, app.ico, app.rc, AssemblyInfo.cpp, stdafx.cpp, and Hello.cpp just for "hello world" lol.

You can create an empty project and add your own *.cpp file(s) to it.

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

I just finished installing Fedora 11 on my 64-bit Vista computer (dual boot) and see that it does not include gcc or g++. I looked on gnu.org, found something that described the gcc compiler package (briefly) but no links to where to download the binaries.

Anyone have links to it?

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

I hope so. Daniweb kills my iphone with all of the ads :(

make a monetary contribution and you won't get those ads.

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

This is news to me, but it has been a while since I used CPP and maybe it has evolved. My understanding is that any class that implements a "pure" virtual function is an abstract class that forces you to define the function or it also becomes an abstract class. I am not aware that you can define a body for the function in your class and still have a "pure" virtual function.

Yes, it is possible.

#include <iostream>
using namespace std;

class animal
{
public:
    animal() {  }
    virtual void speak() = 0
    {
        cout << "meow\n";
    }
    void SayHello1() { animal::speak(); }
    void SayHello2() { speak(); }
};

class dog : public animal
{
public:
    dog() {}
    virtual void speak()
    {
        cout << "Woof\n";
    }
};


int main()
{
    dog d;
    d.speak();
    d.SayHello1();
    d.SayHello2();
   return 0;
}

results:

Woof
meow
Woof
Press any key to continue . . .

NicAx64 commented: can write like this [code]virtual void speak() =0 { //code } [/code] cool +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't need Microsoft's specific approval to download VC++ 2008 Express -- its still freely available at the links previously provided. Just download and use it.

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

Only one computer at a time -- I only have two hands and one brain, which is single-tasking. I can't tap the top of my head and rub my tummy at the same time either :)

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

Can anyone generate the code for me according to the information and code I posted above?

Yes I could, but I won't. Post your attempts to solve it.

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

1. USE CODE TAGS!

2. Move the open statement up outside the loop.

void dptable(int upplimit)
{
    ifstream("favlist.txt");
    for(int i=0; i<upplimit; i++)
   {
       cout<<fs[i].id<<" "<<fs[i].url<<" "<<fs[i].annotation<<endl;
   }
}

3. Delete that ofstream object that you put in main() -- it serves no purpose and may cause problems with the write function.

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

my guess is that the filename is passed to your program as an argument to WinMain(), much like argv in main().

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

It probably doesn't work the second (and subsequent) time around because the file isn't closed, so it can not be reopened. And why would you want to read that file over and over and over .. and over every time you select option #1??? Just read it upon program start and don't worry about it any more.

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

look it up in your textbook ??? Also, read this thread to get the definition of an "implicit argument".

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

1. pass the variable as a parameter to the function.

2. you mean something like this?

void foo(int x)
{
    cout << "x = " << x << "\n";
}

int main()
{
    int n = 123;
    foo(n);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No -- derived class has not been constructed at that point. When an object is instantiated the compiler first calls the base class then all derived classes, working its way up from the bottom to the top of the hierarchy. classes are destroy in the opposite manner.