In a real situation, you would definitely want to use an std::vector and sort() from STL algorithm:
http://www.cplusplus.com/reference/algorithm/sort/
I'm not sure if that is allowed in your assignment, though.
Dave
In a real situation, you would definitely want to use an std::vector and sort() from STL algorithm:
http://www.cplusplus.com/reference/algorithm/sort/
I'm not sure if that is allowed in your assignment, though.
Dave
You were on the right track by including sstream, but then you didn't use it!
Long lists of code like this this:
if (IPd == ip0) {
k = 0;
f0.open ("Node0.txt");
f0 << "I received a packet from Node " << i << "\n"; // write all the packets that node0 recived and from where
}
else if (IPd == ip1) {
k = 1;
f1.open ("Node1.txt");
f1 << "I received a packet from Node " << i << "\n";
}
is almost always a bad idea.
Assume IP is an int (0, 1, ... 15). You can replace about 100 lines with simply:
stringstream ssFileName;
ssFileName << "Node" << IP << ".txt";
f0.open (ssFileName.str());
f0 << "I received a packet from Node " << IP << "\n";
Hope that helps,
Dave
There are literally hundreds of tutorials about pointers online. I'd recommend reading as many as you can and asking here if you have specific questions.
Dave
I'd recommending changing the title of your post. This isn't really that easy of a question (at least to me, haha). You should call it "Detecting splits in a btree"
Dave
My suggestion is to not use OpenGL directly, but rather, use VTK! (http://vtk.org/)
I have been working hard for the last year writing examples, which you can find here: http://www.vtk.org/Wiki/VTK/Examples
There is certainly a learning curve (but there is with OpenGL, too, as you're experiencing), but it's much cleaner than OpenGL once you get the hang of it.
Good luck,
Dave
I use VNL (part of VXL: http://vxl.sourceforge.net/) for my math operations:
Here is the function you'd want:
http://www.lems.brown.edu/vision/vxl_doc/html/core/vnl/html/classvnl__matrix.html#f714bb239b2b1bdbea787b5920ae07f1
In the constructor, you would probably want to set all of the coefficients to 0. The idea is just that you really NEVER want to have unassigned variables. What if you forgot they were assigned in the read function and tried to access them before that? You would end up with a junk value.
Dave
This was just a goof on my part, but it was quite annoying and maybe it could be handled a bit better. I was on a different machine than normal, so I was not logged into daniweb but I didn't realize it. I found an interesting post and spent quite a while writing a reply. When I clicked "post a quick reply" it told me that I was not logged in (correctly). When I clicked "back", my reply was gone (the text box was empty). Is there a way to have the text remain in the box in a case like this?
Thanks,
Dave
Some libraries that you may find helpful:
ITK:
http://itk.org/
VIL (part of VXL):
http://vxl.sourceforge.net/
OpenCV:
http://opencv.willowgarage.com/wiki/
CImg
http://cimg.sourceforge.net/
Hope that helps.
Dave
1) The undefined reference is because you are not linking to SaveData.cpp. Which IDE are you using (Visual studio, etc)?
2) 'retreive' should be spelled 'retrieve'.
3) you seem to still be using the 5th element (element 4), when it is not valid.
4) it seems to work just fine when you change void outputSavedata (int* stats);
to void outputSavedata (int stats[4]);
Sorry, we will not just do your assignment for you. We also cannot teach you all of c++ - you're going to have to give it an attempt and we can help when you run into problems.
getch() is a c language thing:
http://www.daniweb.com/forums/thread11811.html
I think that book was wanting you to include conio.h, but as you will see if you are working in c++ you likely shouldn't be using that.
You cannot just post a bunch of code and expect us to do your assignment.
1) use code tags so the code you do post is readable
2) extract the problem you are having in to the smallest example possible ( < 20 lines) with sample input, expected output, current (incorrect) output, and any errors that are generated)
peter, please use descriptive thread titles in the future :)
Yea, I think that generally the convention is to not include .cpp files. Surely you can make a project with any IDE. CMake is becoming pretty popular - it is a "crossplatform project building" utility - that is, in linux, you can generate a makefile or a KDevelop project. In windows you can generate a visual studio project. It's much much easier than writing makefile yourself for large projects, but for this small of a project I'm sure you could find a makefile tutorial online (this one looks reasonable http://www.opussoftware.com/tutorial/TutMakefile.htm)
Dave
I believe the preferred method of reading all the lines in a file is this:
std::string line;
while(getline(fin, line))
{
//the current line is now in "line", handle it
}
Can you abstract the question to something like "how do you input everything the user types until the enter key is pressed?" or something like that? I'd say 3/4 of those lines are not related to your question. Please post
1) the shortest example possible that demonstrates the problem
2) a sample input
3) the current output
4) the expected output
and then we can probably help :)
Dave
Here are some of the answers:
What is the output of printf("%d")
It will output some junk signed integer value because you never told it which signed integer to output.
Difference between "vector" and "array"?
A vector is a STL container that has the same functionality as an array, but you check the validity of an index using .at() and you can get the length with .size(). You can also use STL iterators to potentially convert a vector into a different STL container.
Can we generate a C++ source code from the binary file?
Sounds hard, if not impossible.
What are inline functions?
Functions that the compiler knows to optimize. I think most compiler usually figure out what to inline by themselves these days.
Details about profiling?
I use valgrind's cachegrind. Works really well/easily.
Not very efficiently, you could simply push the front() element onto the back of the queue, then pop it from the front. Do this until you get to the last element, but simply pop it instead of pushing and popping it. Because of the 'remark' I take it that this is an assignment and therefore you aren't worried about efficiency, just getting it work. Let me know if that's an acceptable solution.
Dave
if you have a very simple program that just has to run a zillion times, you can use OpenMP parallel for loops. You just put a #pragma right before the loop and it magically splits it across all available cores.
You can do more complicated things with openmp, but this is what I use it for.
Dave
Cool, that'll do it. I sorted the points and then used unique.
sort(Points.begin(), Points.end());
vector<Point>::iterator new_end = unique(Points.begin(), Points.end());
Points.erase(new_end, Points.end());
Thanks all.
Dave
You seem to have not tried at all. Give it a shot and then if it doesn't work we'll help you.
But look how easy this is!
ifstream fin(Filename.c_str());
if(fin == NULL)
cout << "Cannot open file." << endl;
vector<string> Lines;
string line;
while(getline(fin, line))
{
Lines.push_back(line);
}
cout << "NumLines: " << Lines.size() << endl;
for(unsigned int i = 0; i < Lines.size(); i++)
cout << Lines[i] << endl;
Is there a way to remove these threads altogether? It really pollutes the forums.
Dave
you could use a vector instead of an array
#include <vector>
then you can return a vector<int> and not have to worry about every saying pointer!
Dave
I am using VS2008. Turns out I was using a library that was using the 80 version of the file.
I used this
http://www.dependencywalker.com/
and it showed me exactly what the problem was! Highly recommended and free!!
Sorry for the confusion.
Dave