Forum: C++ 28 Days Ago |
| Replies: 5 Views: 389 I understand for quick solutions you would follow AncientDragon's sage advice.
However, that always leaves a sour taste since I am sure your want to know how to do it:
So here goes
... |
Forum: C++ Nov 8th, 2009 |
| Replies: 2 Views: 348 I think that you have got confused with the syntax of declaration and implementation. So here is an example with most of the common things you will likely need. [Please ask if I have missed... |
Forum: C++ Nov 8th, 2009 |
| Replies: 12 Views: 464 I agree with Jonsa's point you can put [icode]using std::cout; [/CODE] etc, although it is important to remember that they can be put within a scope, e.g. in a function and not the global scope.
... |
Forum: C++ Nov 8th, 2009 |
| Replies: 12 Views: 464 Well DONT use using namespace std;
You can write it like this:
std::ofstream File("Output.txt")
File<<"This is to the file"<<std::endl;
std::cout<<"Written line to the output file"<<std::endl;... |
Forum: C++ Nov 8th, 2009 |
| Replies: 12 Views: 464 First: USE CODE TAGS
Second: you don't not have to declare the variable name in definitions e.g. void resultsfn(int& A); is the same as
void resultsfn(int&);.
This often makes code clearer
... |
Forum: C++ Nov 1st, 2009 |
| Replies: 4 Views: 386 The bovious thing to do is to run it in the debugger e.g. gdb or ddd
Compile with g++ -g -o Prog prog.cpp, and the run as ddd Prog. When it hits the seg-fault, use up until you see the problem... |
Forum: C++ Oct 27th, 2009 |
| Replies: 4 Views: 232 Well you don't seem to have written a operator>> for class ballTeam. I could be wrong since you didn't include the definition files (.h files).
I |
Forum: C++ Oct 25th, 2009 |
| Replies: 4 Views: 196 This is code absolutely begging for a loop!!
Your actual problem is that you test x then y. That is incorrect. (I think)
Consider a box with coordinates (0,0) and (10,10). I.e it is a square of... |
Forum: C++ Oct 25th, 2009 |
| Replies: 2 Views: 344 The problem you have is temporary values and what happens to them:
I think this will be clear (I hope :)
The problem is that your are taking a copy of the value in the list. This does indeed... |
Forum: C++ Oct 21st, 2009 |
| Replies: 12 Views: 495 If you are debugging code (and that is what you are doing here), you need to step through the code and check your assumptions. That can be done with a traditional debugger that lets you see each line... |
Forum: C++ Sep 27th, 2009 |
| Replies: 2 Views: 910 The normal way to do this is to use a stringstream.
Now you have to be VERY VERY careful, with this.
The reason is that if you do
double Res;
std::string A="3.4e5x"
std::stringstream IX(A);... |
Forum: C++ Sep 26th, 2009 |
| Replies: 3 Views: 353 Ok there are many many thinks to really really dislike about this code.
In particular is the "cleverness".
Ok first, it is int main(). That has been said a million times on this forum.
... |
Forum: C++ Sep 25th, 2009 |
| Replies: 4 Views: 897 Actually, if you are doing a binary search, make 100% certain that you understand the algorithm in 1D. That is important since 2D array can be easily thougth of as a 1D array. The binary search can... |
Forum: C++ Sep 25th, 2009 |
| Replies: 4 Views: 897 Note 100% certain I follow what you are trying to do.
But some points:
(a) C++ is almost space insensitive. The only areas you have to worry are in the middle of keywords e.g. cla ss A { } is... |
Forum: C++ Sep 21st, 2009 |
| Replies: 4 Views: 278 Can you post your new non-compiling/non-running code please.
The only thing that I can think you might have done wrong is to forget to at const to both the declaration and the instance eg.
... |
Forum: C++ Sep 20th, 2009 |
| Replies: 4 Views: 278 This is simple (I hope). You are using an iterator. The iterator allows the method to change the data.
Now since an iterator is a class and your compiler cannot know until link time that the... |
Forum: C++ Aug 16th, 2009 |
| Replies: 3 Views: 418 Let me just add, since i is declared as a double , your loops are complete and test with i==1000 are complete junk.
If you add 1 to a double at about 1e16 this is true:
// True on some machine... |
Forum: C++ Aug 14th, 2009 |
| Replies: 1 Views: 205 A multitude of errors, mostly caused by trying to write everything in on go.
(a) Patient includes an instance to Doctor. Therefore you must have a declaration of Doctor before Patient is declared.... |
Forum: C++ Jul 8th, 2009 |
| Replies: 7 Views: 305 Some comments:
First yes, one of the original ideas was to only write code once. [it was actually discussed in terms of macros but it still holds]
(b) #include <limits> gives the absolute best... |
Forum: C++ Jul 7th, 2009 |
| Replies: 7 Views: 305 I normally think it is better to wrap these kind of fabs() type test
in a testing namespace , that provides a template form like this
namespace Approximate
{
template<typename T>
bool... |
Forum: C++ Jun 14th, 2009 |
| Replies: 9 Views: 649 I really don't think that the problem is with string. Examining you code fragment, buffer2 obviously has size (you could test this with a
std::cout<<"Length of buffer2 ==... |
Forum: C++ Jun 13th, 2009 |
| Replies: 9 Views: 649 If you don't want to post your code, then maybe a cut down version. But the quickest way to do it yourself is to compile with debug info on and then run and wait till it crashes. The backtrace will... |
Forum: C++ Jun 10th, 2009 |
| Replies: 4 Views: 533 Several things from your question:
First the string part. You have many options (a) you can indeed use
insert but the method requires an iterator to define the position for insertion. (b) the... |
Forum: C++ Jun 3rd, 2009 |
| Replies: 4 Views: 258 This is C++ not C, so I would have written:
b= -1*static_cast<int>(x)/2;
The main advantage of this is the you have an explicit bracket around the section you are casting and it is a BIG... |
Forum: C++ Jun 3rd, 2009 |
| Replies: 6 Views: 238 Well the problem seems to be that you expect the array to be terminated with a 0 . This is a mess.
What I think you have done is confuse the normal mechanism for strings e.g.
char* X="Fred";... |
Forum: C++ Apr 12th, 2009 |
| Replies: 4 Views: 363 Looks to me that you are not creating an instant of the template class
for <int>.
You have put the link body in a .cpp file. That is perfectly acceptable and good practice if the body is large.... |
Forum: C++ Mar 15th, 2009 |
| Replies: 3 Views: 377 Well depite the fact that this looks awful, you almost definately have a
memory leak. You initialize line to fslen+10, whatever fslen is. Then you do not delete it.
However, as vmanes says, you... |
Forum: C++ Mar 12th, 2009 |
| Replies: 4 Views: 1,093 I think you have made a mistake in your question. If you have
0..25 in your code your compiler will tell you that it is an error.
However, if you are trying to go from a string to a number the... |
Forum: C++ Mar 8th, 2009 |
| Replies: 3 Views: 548 Answer is: Start again
You have
while (getline(cin, info) && info != "")
{ if ( isInVec(word[info.length()], info) == false)
word[info.length()].push_back(info);... |
Forum: C++ Mar 5th, 2009 |
| Replies: 4 Views: 1,405 You can't copy it to a set and back again without breaking the order.
Sets store on a compiler defined manor but normally red-black trees.
Hence you will destroy the order.
The easiest way is to... |
Forum: C++ Mar 2nd, 2009 |
| Replies: 7 Views: 489 You don't seem to have posted enough code for anyone to tell but are you using:
m_pEcoAreaTeam = new EcoAreaTeam();
and then the class does not have m_pEcoAreaTeam and you have a scope issue??
... |
Forum: C++ Feb 18th, 2009 |
| Replies: 7 Views: 1,193 First off, well done for using code tags for your first post.
Second, your error is that you are returning 0 but actually need to return a string.
Try as the last two lines of padBlanks, this:... |
Forum: C++ Feb 12th, 2009 |
| Replies: 4 Views: 363 I thinks you just need to add { } round the loop part.
You add up count each time but then only output n at the end.
If you output n for each step of the loop you will get exactly what you want. |
Forum: C++ Feb 9th, 2009 |
| Replies: 9 Views: 826 I am a bit lost: You cannot create a class from template parameters that are not known at compile time. For example
template<int N>
class A
{ };
You can't have A<i> and since you will only ... |
Forum: C++ Feb 7th, 2009 |
| Replies: 9 Views: 826 Well first off, I accept that you didn't get any replies at the previous forum, so I will accept that you should re-post. (I might have waited another day or so but that is minor). Given that, I... |
Forum: C++ Feb 3rd, 2009 |
| Replies: 11 Views: 442 errh... sorry Ancient Dragon, but the last line of the file is just "="?
Which was what I was trying to allude to.
The probelm seems to me to be that you read that with a statement... |
Forum: C++ Feb 3rd, 2009 |
| Replies: 11 Views: 442 You have a problem at the last line of your input file.
You read while(partin >> charInput >> numInput)
and you have just = on the last line so it reads into charInput and then waits and... |
Forum: C++ Feb 1st, 2009 |
| Replies: 6 Views: 430 well we still can't figure it out since I am certain that most of the members of this forum are not psychic.
You have not posted code that actually compiles, so I cannot guess what your real code... |
Forum: C++ Jan 31st, 2009 |
| Replies: 5 Views: 433 Sorry the two different names, addTip and addBill was my mistake.
They should be the same. I just wrote it in the message window (not a very good excuse.)
Your problem is that you really haven't... |
Forum: C++ Jan 31st, 2009 |
| Replies: 6 Views: 430 No:
The question what is tempData, was because it is declared string but you are comparing it with an integer.
What you have posted DOES NOT COMPILE, hence we can't debug it. What you have to... |