1,426 Posted Topics
Re: Well if you need dynamic c-string arrays I would suggest using string from the STL. as far as an a array of structures thats pretty simole too. you can use a hard coded array or you can use one of the containers avalible in the STL. In this case a … | |
Re: if you have a vector of floats you might want to use the for_each function in the algorithms header. | |
Re: you have your code like this [code=c++] int firstNo;// first number is stored here int secondNo, int resultAdd,// variable for result when first number and second number are added int resultSub,// variable for result when first number and second number are subtracted int resultMult,// variable for result when first number … | |
Re: What compiler are you using? also the way to define the standard headers is to not include a .h after it. [code=c++] #include <iostream> #include <ctime> #include <string> #include <vector> //... [/code] | |
Re: well if you want to convert a char to an int you have to do this [code=c++] char temp = '2'; int number = temp - '0'; // number is now 2 // if you do this int number = temp; // number is now 50 [/code] | |
Re: [URL="http://www.cprogramming.com/tutorial/cpreprocessor.html"]macros[/URL] | |
Re: you can always use the next_permutation function located in <algorithm>. As mike said you will need to break up then number into each digit and put them into some kind of container. Vectors work well for this. then you will need to sort the container to have the smallest digit … | |
Re: Does this program run correctly? Lines 57-75 looks like it is an infinite loop. On lines 97 and 98 you have 2 return statements. You can only return one thing from a function. This is not to say you cant have a multiple returns in a function, you just cant … | |
Re: Do you really need to use strcmp? String's have a built in operator == that you can use for comparison. [code=c++] std::string foo = "foo"; std::string bar = "bar"; if (foo == bar) std::cout << "foo and bar are equal."; else std::cout << "foo and bar are not equal.": [/code] … | |
Re: @ Nandu Das The purpose of this forum is to help not to just give you the code. If you are having a particular problem with this problem then state what that is and we can help. With that said you can do this very simply. you will need three … | |
Re: I am sad that he will not be with us anymore. He had given me some wonderful advice and wasn't afraid to call me out if what I said was incorrect. He will be missed | |
Re: the problem is the chicken and the egg paradox. what comes first in your code A or B?. if A is first and A uses B then the compiler goes to B to find out what B is but B has A in it and A isn't finished so it … | |
Re: @ sourabhtripathi [icode]*p2--;[/icode] does not change the memory address. it actually is subtracting 1 from the value stored at p2. also you don't have the values initialized to anything. here is a link for you. [url]http://www.cplusplus.com/doc/tutorial/pointers/[/url] | |
Re: @firstPerson The link you provided states that both list must be sorted by a strict weak sorting method. So the OP would have to call [icode]sort()[/icode] on his list first before he sends them to [icode]std::set_difference[/icode] | |
Re: In your build log it shows its compiling 2 playerhandeler.cpp and 2 main.cpp. maybe something going on there. | |
Re: What happens if you do this? [code=c++] ofstream f1("s.dat", ios::binary); //... output to file here f1.close(); [/code] | |
Re: Why are you using c functions in c++ code? Also you are mixing strings and char arrays. Is there a reason for that? Lastly you should not use eof() for you while loop. Just use your getline staement for your while condition. | |
Re: How is your matrix defined? If it is a class than you can put it into a [icode]std::list[/icode]. Also you can add a get funtion to your class that will return the element you are looking for. [code=c++] class Matrix { //... int GetData(int row, int col); // returns the … | |
Re: What exactly is the LNK2019 error saying? | |
Re: I looked at the book and it looks like since there are multiple keys that are the same the author decided to have each rule be in a vector. That way you have one key "adjective" and then a vector that has 3 different rules in it. This way one … | |
Re: The reason this is happening is there is a newline left in the buffer from line 145. when you call getline() in you accessUNIT() function it reads in the newline and that's all. To fix it put [icode]cin.get();[/icode] on line 146. Try reading [URL="http://www.daniweb.com/forums/thread90228.html"]this[/URL] for more information. | |
Re: Do you have a tree already or do you need one? Also what type of data does the file have? What I mean by that is, is child1 a string or something else you are just calling it child1? | |
Re: Lines 21 and 22 are wrong. They should be [code=c++] hasSetPages = new bool; hasSetColor = new bool; [/code] | |
Re: I would re write your function like this [code=c++] string backwards(string input) { string temp; for (size_t i = input.size() - 1; i >= 0; i--) temp += input[i]; return temp; } // then in you main function cout<<"Input backwards is : " << backwards(input); [/code] FYI size_t is the … | |
Re: What exactly do you want to do if there is a non number in the string? that will determine what you need to do. | |
Re: you can use string streams to do this but you will to be able to put that number into an int. An int only holds integer values. You will need to put it into a double or float data type. [code=c++] #include <sstream> // you will need this to use … | |
Re: if you use strings' [icode]find_first_of()[/icode] to locate the < you can store the position of the < in a variable and then call [icode]find_first_of()[/icode] for > starting at position + 1. [code=c++] size_t firstPos = 0, secondPos; string temp = "4ab030 <__do_global_ctors_aux>"; string sub; if ((firstPos = temp.find_first_of("<", firstPos)) != … | |
Re: I think the problem is coming from the way you are using your if...else statements. On line 54 you check to see if the area is greater than 750 and if it is you add your base_cost with 750 and store it into total_cost but if its not you don't … | |
Re: The way you have declared the templated function is wrong. if your function is a void function then instead of this [code=c++] template <class T> REGISTER_BUILDER<T>(Builder, T, "RecoBuild", ViewType::kAll3DBits);//(name, type, purpose, view) [/code] Try this [code=c++] template<class T> void REGISTER_BUILDER(Builder, T, "RecoBuild", ViewType::kAll3DBits);//(name, type, purpose, view) [/code] When you template … | |
Re: If you have long lines that go off the screen just separate it onto multiple lines [code=c++] for (thisReallyLongVariableName = anotherVeryLongName; thisReallyLongVariableName < somethingRealyComplex; thisReallyLongVariableName += moreOfTheSameStuff { //... [/code] | |
Re: I believe this is because your function names and your variable names are the same. try changing all of your function names to start with a capital letter [code=c++] double Radius(double x, double y, double xs, double ys); double Diameter(double x); double Circumference(double x); double Area(double x); // instead of … | |
Re: can you post your current code that you have now? | |
Re: you could always write your own dynamic array class and use that to store the input into it then add up all of the digits. I'm not sure if that would be considered cheating since it uses the same approach as the STL. | |
Re: First void main is a big no no. main should return an int and only an int. Second [icode]<iostream.h>[/icode] is depreciated and should not be used as well. You should use [icode]<iostream>[/icode]. Lastly please use indentation in you code. It makes it much easier to read. | |
Re: Pretty nice page from what I have read so far. Good job. You might want to add the output created from the program just to be a little extra helpful. | |
Re: You can use string streams to convert a string into a number. [URL="http://programmingexamples.net/index.php?title=CPP/StringStream"]this is from dave's new wiki[/URL] | |
He all I am currently working a on a problem to convert the entire contents of an STL container into a string. For example if I had this: [code=c++] int foo[] = {1, 2, 3, 4, 5}; vector<int> bar(foo, foo + 5); [/code] I would like to convert [icode]bar[/icode] into … | |
Re: Try wrapping the for loop in parentheses. I also split the macro into multiple lines. [code=c++] #define forallXNodes(u,G) \ (for(arc *bfs_ee=(G.getSource())->firstOutArc(),arc *bfs_stopA=\ (G.getSource())->lastOutArc(),u=bfs_ee->head(); bfs_ee <= bfs_stopA;u =\ (++bfs_ee)->head())) [/code] | |
Re: @ OP If your compiler evaluates both functions in this code than I suggest you get a new one. [code=c++] #include <iostream> using std::cout; bool returnTrue ( ) { cout << "ret TRUE\n"; return true; } bool returnFalse( ) { cout << "ret FALSE\n"; return false; } int main() { … | |
| |
Re: [URL="http://www.daniweb.com/forums/thread70096.html"]books[/URL] | |
Re: Your program starts to fall apart with numbers larger than 15. You might want to rethink your algorithm. | |
Re: what would happen if you change you include section to look like this [code=c++] #include <iostream> #include <cstdlib> #include <stdio.h> #include <assert.h> using namespace std; [/code] | |
![]() | Re: Making a 2d array for this is pretty strait forward. Because you don't know how many duplicates are in the array you would need to have an array like [code=c++] int ** twoDarray = new int*[size]; for (i = 0; i < size; i++) towDarray[i] = new int[1]; [/code] Now … |
Re: Sorry this is a little of topic but does Ein have anything to add to the conversation Edward? | |
Re: Just start off with a blank vector and push the objects on. [code=c++] class Foo { // ... } int main() { vector<Foo> container; for (int i = 0; i < 10; i++) { container.push_back(Foo()); } } [/code] | |
Re: I think what you are trying to do is input a word and see if any part of that word matches what you have in a text file. now do you want only sequential letters to make the work or can it be any combination of letters in the inputted … | |
Re: @ VirtualAssit Its nice to see that you are trying to help but please use code tags. Secondly the code that you posted is non standard. void main() is a big no no. main should only return an int according to the c++ standard. The function clrscr() you used is … | |
Re: well you have a doubly linked list so in reverse start at the last node and then traverse your way backwards by calling previous. |
The End.