daviddoria 334 Posting Virtuoso Featured Poster

You could also use an 'enum'. This lets you see words rather than numbers when writing the code, but everything is translated to an int at compile time.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You really shouldn't be scared of STL containers. They will save you tremendous amounts of time (in exactly cases like this!) Rather than thinking of it as "learning maps and arrays at the same time" you should see this as an opportunity not to get stuck in the array way of thinking of things (as I had done for years before I was introduced to STL containers!) and consider it a good time to learn about containers/data structures. There is not really a hierarchy (array before set, before map, etc) - they are all on equal ground, just have different uses.

If I couldn't use a map, my second option would be this:

1) Store the input array in an std::vector.
2) Copy the input vector into a std::set. This removes all duplicate elements
3) Create a vector the same size as the set. This is where you will store the count of each unique element
4) Iterate over the set and use std::count (from STL <algorithm>) on the original vector, searching for the current element in the set
5) Store the result in the ith position of the vector you created in step 3.

This is exactly what a map would be doing :)! The algorithm would be much more involved if you only wanted to use arrays (vectors), as you'd have to do the uniqueness checking and counting manually.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Hi Andrew,

Unfortunately I don't know the answer to your question. However, I urge you to make the titles of your threads as descriptive as possible. For example, I came to look at "A little problem", but quickly found out that it was related to the Windows API and I don't know anything about that. If you named it something like "Determine which key was pressed with WH_KEYBOARD hook", I would have known to leave it to the Windows guys :)

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

Haha while I'm sure all of us have partaken in our share of mischief, surely we did not openly advertise our "black hat" goals. You could certainly have asked us a "white hat" question - "How do I copy a file from XYZ language" and your motives would have never come into question.

Again, you are not paying attention. This is not the place for VB questions.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I would look into a GUI system such as Qt4. This will allow you to make professional looking applications.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I was hoping for something that I could compile and poke around at :)

daviddoria 334 Posting Virtuoso Featured Poster

Both functions should simply return an int (by value). Simply change void FunctionName() to int FunctionName() and at the end of the function, after you cout << something; now you need to return something;

daviddoria 334 Posting Virtuoso Featured Poster

I would indeed try to make a "20-line" demo of the problem that you can post for us.

daviddoria 334 Posting Virtuoso Featured Poster

13 or not, please use real English works (e.g not "every1", "meh", "skript").

daviddoria 334 Posting Virtuoso Featured Poster

Ganty722,

Welcome to DaniWeb!

I recommend looking into ifstream. Once you do that if you still have problems post the code of what you've tried here and we'll see if we can help you figure out what is wrong.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This error typically means that the file clientList.cpp is not linked to by the project. Try to produce the fewest lines of code that will produce this message and we can check if anything else looks wrong of if the project is simply mis configured.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Here is how to iterate through the whole map:

void IterateOverWholeMap()
{
  std::map <std::string, int> myMap;
  myMap["testone"] = 111;
  myMap["testtwo"] = 222;
  
  std::map<std::string,int>::iterator iter = myMap.begin();
    
  for(; iter != myMap.end(); ++iter) 
  {
   std::cout << iter->first << " " << iter->second << std::endl;
  } 
}

Here are some more notes I have:

void SetValue()
{
	//create a map
	std::map <std::string, int> MyMap;
	
	//create a mapping from "test" to 111
	MyMap["test"] = 111;
}

void SetAndGetValue()
{
	//create a map
	std::map <std::string, int> MyMap;
	
	//create a mapping from "testone" to 111
	MyMap["testone"] = 111;
	
	//create an iterator
	std::map<std::string,int>::iterator iter;

	//try to find "testone"
	iter = MyMap.find("testone");
	
	//we assume "testone" was found, so output the value that "testone" maps to
	std::cout << iter->second << std::endl;
}

void ResetValue()
{
	std::string Name = "testone";
	std::map <std::string, int> MyMap;
	MyMap[Name] = 111;
	
	std::map<std::string,int>::iterator iter;

	iter = MyMap.find(Name);
	
	double FirstValue = iter->second;
	std::cout << FirstValue << std::endl;
	
	MyMap[Name] = FirstValue + 1;
	
	double SecondValue = iter->second;
	std::cout << SecondValue << std::endl;
	
}

void NonExistentValue()
{
	std::map <std::string, int> MyMap;
	MyMap["testone"] = 111;
	
	std::map<std::string,int>::iterator iter;

	iter = MyMap.find("testone");
	
	if(iter == MyMap.end())
	{
		std::cout << "Element not found!" << std::endl;
	}
	else
	{
		std::cout << "Element found!" << std::endl;
		std::cout << iter->second << std::endl;
	}
}

Be sure to vote here: http://daniweb.uservoice.com/forums/62155-general/suggestions/830529-create-a-wiki-to-catalog-answers-and-examples-?ref=title so we can catalog examples like this!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

They are really, really useful! Try not to get caught up in the template/iterator terminology. The main idea is the key->value associations. In this case, the key is the number you want to know how many times has occurred, and the value is the number of times it has occurred. When you insert something into a map, if it is already in the map, nothing will happen. If you want to be able to map a key to multiple values, there is a std::multimap.

Let us know if you have any questions -

Good luck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

That is exactly what a map does, except it doesn't waste space with numbers that have count = 0.

daviddoria 334 Posting Virtuoso Featured Poster

Ah I see. Will do.

daviddoria 334 Posting Virtuoso Featured Poster

For that question, I'd start here : http://www.daniweb.com/forums/forum4.html

However, I'd ask why you would want to use such an old language?

daviddoria 334 Posting Virtuoso Featured Poster

You should use the count() function from STL algorithm

#include <algorithm>

start = Vect.begin() ; 

end = Vect.end() ;
result = count(start, end, value) ;

(There is also a sort() function, but you shouldn't need it here)

If you wanted to do it more manually you should use an std::map.

Be sure to vote for cataloging answers like this, I've definitely answered this one before :) http://daniweb.uservoice.com/forums/62155-general/suggestions/830529-create-a-wiki-to-catalog-answers-and-examples-?ref=title

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Or you should have just learned c or c++ in your course! As nbaztec recommended, if you have specific questions we'll be glad to help if you demonstrate that you have thought about/tried them yourself first.

daviddoria 334 Posting Virtuoso Featured Poster

Please post

File1.cpp

//file1.cpp here

File2.cpp

//file2.cpp here

So the next guy knows where you are so far.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You absolutely should not #include "file2.cpp" . Since you're using visual studio the linking should be setup automatically for you - but I'll let a VS user reply with the details.

daviddoria 334 Posting Virtuoso Featured Poster

One helpful hint - please use a descriptive thread title, for example instead of "HELP!!!!!", say something like "Trouble with input and if statement".

Dave

daviddoria 334 Posting Virtuoso Featured Poster

That is a pretty serious application! I would certainly not start out with something anywhere near that complex! I'm not even sure c++ would be the right language to start a project like that with.

daviddoria 334 Posting Virtuoso Featured Poster

Just #include <cstdio> in file2.cpp.

daviddoria 334 Posting Virtuoso Featured Poster

(Sorry, double post)

daviddoria 334 Posting Virtuoso Featured Poster

See also: http://www.daniweb.com/forums/thread117408.html

And again: This is another one of those "common" questions that I am recommending cataloging:

http://daniweb.uservoice.com/forums/62155-general/suggestions/830529-create-a-wiki-to-catalog-answers-and-examples-?ref=title

Please vote for it!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

A couple of more things

1) DaniWeb Digest Prominence: http://daniweb.uservoice.com/forums/62155-general/suggestions/844285-make-daniweb-digest-more-prominent?ref=title

2) Almost everyone chatting here has thousands of posts. I'd strongly recommend you link to this thread from EVERY forum/subforum so that all users (including less geeky ones that don't check the Community Feedback forum!) can have a say.

3) It would be nice to be able to specify the number of posts per page. Sometimes it would be convenient to display 30 posts on one page so I can scroll up and down to follow long conversations : http://daniweb.uservoice.com/forums/62155-general/suggestions/844293-allow-variability-in-number-of-posts-per-page

4) There is an "edit/delete" button for the first 30 mins after a post. However, it doesn't seem to give the ability to delete (at least for non-mods). Should it just say "Edit" if the users doesn't have delete power? It actually makes sense to give delete power to a users own posts (again in the short period after the post) to prevent double posting.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is it just this "Receive Occassional Email from DaniWeb"? If so, then that is exactly my point! It doesn't say anything about DaniWeb Digest!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This is another one of those "common" questions that I am recommending cataloging:

http://daniweb.uservoice.com/forums/62155-general/suggestions/830529-create-a-wiki-to-catalog-answers-and-examples-?ref=title

Please vote for it!

Dave

iamthwee commented: No -2
daviddoria 334 Posting Virtuoso Featured Poster

vb5prgrmr - RELAX man! The other 750,000 users seem to be enjoying their time here. Dani is clearly showing an effort to correct any "wrong" that you claim may have been done by, as she said, asking for viable solutions to the "problems".

Dani, Davey -
I actually haven't been able to find how/where to sign up for the DaniWeb Digest. (granted I haven't looked TOO hard). I would suggest putting it somewhere more prominently so more people sign up!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

VirtualAssist,

Welcome to DaniWeb! Thanks for posting a solution to this question! In the future, can you please be sure to use code tags around code? It makes it MUCH more readable for everyone.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

UncleLeroy,

This is certainly an assignment (I hope!). If I'm wrong, then DEFINITELY use std::list!

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand what he is expecting you to do, then? Make a little 2D treadmill for a mouse with a ball that you control to physically move the cursor??

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

Yep - I have only posted once or twice on Stack Overflow so I guess I didn't even realize they used it! It is ultimately much more flexible - folders/subforums are a strict subset of labels/tags. This allows for perfect backward compatibility - you could leave the structure that you have in place, just when a user clicks "c++" under "software development", it would just show them all of the threads with the c++ label. This allows "old school" users to go about their business without even knowing anything changed. But "bleeding edge" users could take advantage of mutliple-labels on a thread. Basically it lets 2x (or more) the audience see relevant posts. There are certainly plenty of times when a post could go in both "game design" and "c++" (just as a silly example). I would never see the post if it was only put in "game design" (since I am a c++ dweller), but I would if they tagged it as "game design + c++".

daviddoria 334 Posting Virtuoso Featured Poster

Here are a couple of things:

1) If you want to be a bit adventurous, I've heard of the concept of "labeling" threads (as gmail does) rather than putting them in subforums (folders, following the gmail vs traditional email example). I noticed your thread discussing how you re-arranged some subforums - with this style that would not be necessary.

2) On sites like (or based on) stackoverflow, there is the ability to mark a response as the "answer". This is very helpful.

3) Let me re-suggest using uservoice (http://www.daniweb.com/forums/thread289892.html) to catalog this type of thing (i.e. to replace this thread!)

4) Let me re-suggest cataloging problem solutions as examples on a wiki (http://www.daniweb.com/forums/thread284749.html)

Let me know if you want any further explanation or clarification of these ideas!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This looks like a terrible idea! :) char ss[32556]; Why not use std::string instead?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

jeffpro,

Welcome to DaniWeb!

SetCursorPos() seems reasonable, too bad you can't use it! Which operating system are you using? That is definitely going to dictate how you need to go about this.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Any Drupal users out there??

I have created several articles ("Article1", "Article2", etc) and I want to display them on the page called "Projects". Someone told me to look at "views". I went to "structure->views" and there are a bunch of options such as "archive", "backlinks", "comments", etc. but I didn't know which one of these to choose.

When you go here:
http://doriad.myrpi.org/Personal/

It does exactly what I am trying to do - Article1, Article2, etc are all "stacked on one another and displayed simultaneously. I want to do that, but on the Projects page http://doriad.myrpi.org/Personal/node/6

Any thoughts?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Hi Grusky, welcome to DaniWeb!

First, maybe studying the name will be a good place to start. "Linked list" indicates that there are some kind of pieces (elements in the list) that are "linked" together. There is a pretty good description here: http://en.wikipedia.org/wiki/Linked_list. I'm not an expert, but without a doubly-linked list, you'll have to go through the whole list and store each element somewhere before you can reverse the list.

Can you explain what you have tried to do so far for the reverse() function?

Good luck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You should look into ifstream and cin and the >> operator.

daviddoria 334 Posting Virtuoso Featured Poster

(please remember to close you code tags with /code :) )

What is all this business you're doing with typedef and size_type? None of that should be necessary here if I've understood the problem correctly?

What does the variable name "aantal" mean?

I'm not sure what this condition is doing?

while ( aantal 2 <> aantal *5 )

Yes, you want there to be 5 times the number of grades as names, but you don't want that to be the main loop condition, right? You want the main loop condition to be how many names should be entered, no?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

It sounds like you should make a 'student' class, something like this:

class Student
{
public:
 std::vector<double> Grades; //will be length 5
 std::string Name;
 void InputGrades();
};

Then from the main program, you have to do something like this:

std::vector<Student> students;

while(more students)
{
Student currentStudent;
currentStudent.InputGrades();
students.push_back(currentStudent);
}

Good luck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand what you mean by the "vector must be 10", "the vector must be 14", etc.

Can you clarify?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

vsawant -

Welcome to DaniWeb! Let me give you a few pointers to ensure your stay here is as successful as possible.

1) Please do not "hijack" threads. That is, your post here was not related to the original question. In this case, you should start a new thread rather than reply to this one.

2) The learning process goes more smoothly if you show us what you have tried so far and we help you get it to work. You will not get many responses just by telling us what you are trying to.

In this case, I would recommend that you look into the modulo operator (%). Note that [even numbers] % 2 = 0 !

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

hisugan -

Welcome to DaniWeb!

Here is a very good collection of demonstrations of many concepts in c++: http://www.java2s.com/Code/Cpp/CatalogCpp.htm

Ketsuekiame -

Let's all play nice! He is new here, he'll get the hang of it :)

daviddoria 334 Posting Virtuoso Featured Poster

I use KDevelop4.

daviddoria 334 Posting Virtuoso Featured Poster

I'm sure this is not helpful, but as a data point for you this runs fine for me.

#include <iostream>
#include <cstdio>
#include <cstdlib>

int main()
{
  system("/usr/bin/firefox");
 
  return 0;
}

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I use linux and QT. It is annoying to figure out for the first time, but it is really nice once you get used to it.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This compiles fine for me:

#include <iostream>
#include <cstdio>

int main()
{
 printf("teste");
 return 0;
}

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to DaniWeb!

To make your time here as successful as possible, allow me to recommend a few things:

1) Remember to close your code tag :)
2) Use a descriptive title (i.e. Not "A problem", but rather "A short summary of the specific problem".
3) Try to post < 20 lines of code. Be sure that they compile though! You should try to abstract the problem into a very generic situation that we can help you with, rather than helping you on an enormous chunk of real code.
4) If the problem really does need all of the code, attach the files to the thread. This way we can just download them instead of having to create all the files ourselves and copy and paste the contents.

Once you post the files we'll take a look.

Dave