1,177 Posted Topics
Re: I didn't look closely, but my first thought is to try std::vector<std::string> - is there a reason you need it to be std::vector<char*> ? Dave | |
Re: Can you show us your readin function and then the function that is not retrieving the correct values? | |
Re: Here is an example of how to use a struct: [code] #include <iostream> struct Card { int id; }; int main (int argc, char *argv[]) { Card c; c.id = 3; return 0; } [/code] It is exactly like a class, but the default member level is public. I think … | |
Re: It is very unlikely that someone is going to look through your 300 lines of code. Please whittle the code down to a ~20 line compilable example of the problem, along with sample input, expected output, and current (incorrect) output. Dave | |
Consider these functions: [code] void OperateOnDoublePointer(double* a) { std::cout << a[0] << std::endl; } void OperateOnFloatPointer(float* a) { std::cout << a[0] << std::endl; } [/code] This works as expected: [code] double* c = new double[1]; c[0] = 3.3; OperateOnDoublePointer(c); [/code] but when I try to do this: [code] double* c … | |
Re: To delete an element from anywhere, you'll want to use a linked list (std::list) instead of an array. Google "data structures" and you should find some overviews of when/why to use lists/maps/vectors/queues/stacks. Each has advantages and disadvantages. Hope that helps, Dave | |
Re: You need to change [code] int a[]= new a[10]; [/code] to this: [code] int* a = new int[10]; [/code] also, you have "i" as the counter variable in both the outer loop and inner loop, that is definitely going to cause problems. Dave | |
Re: If you don't want to do your homework, why would we? Give it your best shot and someone will help you if you get stuck on a particular problem. | |
Re: Can you post a compilable example of your problem? | |
Re: In general, you should post only code relevant to the question you are asking. For example, here you basically just want to know how to read words from a file, and that has nothing to do with hangman. This is how I would do it: [code] std::ifstream fin(Filename.c_str()); if(fin == … | |
Re: Can you post a bit more code (the shortest compilable example)? Personally, I anytime I see **, I think there is a better way to go. Maybe you could use an std::vector<int*> or something like that? | |
I am trying to parse the content of a wiki page. In a string like this: [code] ==Heading1== <test> some text here </test> ==Heading2== <test> even more text </test> [/code] I need to obtain "Heading1", "some text here", "Heading2" and "even more text". I got this to work: [code] import … | |
Re: You should definitely use std::vector instead of basic arrays. No one is going to help you unless you show that you have tried yourself first. Dave | |
Re: Please use code tags when you post code. It looks like you need to change this: [code] void myfunc(char scrpt[i]) [/code] to this: [code] void myfunc(char* scrpt) [/code] and this: [code] myfunc(scrpt); [/code] to this: [code] myfunc(&scrpt); [/code] Dave | |
Re: So you WANT to wrap around? Or you don't? Please post your code, input, expected output, and current (incorrect) output. Dave | |
Re: Is this what you're looking for? [code] #include <iostream> #include <map> int main(int argc, char *argv[]) { std::multimap <int, double> MyMap; //create a mapping from "testone" to 111 MyMap.insert(std::pair<int, double>(1, 1.2)); //create an iterator std::map<int, double>::iterator iter; iter = MyMap.find(1); if(iter == MyMap.end()) { std::cout << "Not found." << std::endl; … | |
Re: In SubAbstractSort.cpp, you need to change [code] void sort(int*arr, int size){ [/code] to [code] void SubAbstractSort::sort(int*arr, int size){ [/code] You also need to define the implementation in SubAbstractSort.h [code] class SubAbstractSort: public AbstractSort { public: SubAbstractSort(); int getNumComparisons(); virtual ~SubAbstractSort(); void sort(int*arr, int size); }; [/code] Hope that helps, Dave | |
Re: People are not going to do your homework for you. Please figure out a concise statement of a problem you are having and you'll get a lot more help here. Dave | |
I am trying to strip a prefix from a string, e.g. turn [code] VTK/Examples/Test [/code] Into [code] Test [/code] Sometimes the string does not contain the prefix, in which case I would expect nothing to happen. However, [code] >>> S="Main Page" >>> S.strip("VTK/Examples/") 'Main Pag' [/code] You can see that … | |
Re: It works fine for me: [code] std::string MyString = "hello,world123"; std::cout << "Original: " << MyString << std::endl; //Remove all punctuation MyString.erase( std::remove_if(MyString.begin(), MyString.end(), &ispunct), MyString.end()); std::cout << "Punctuation removed: " << MyString << std::endl; //Remove all numbers MyString.erase( std::remove_if(MyString.begin(), MyString.end(), &isdigit), MyString.end()); std::cout << "Numbers removed: " << MyString … | |
Re: I'm not sure which grid/cells you are talking about? To your title, here is how to draw text in opengl: [code] #include <iostream> #include <cstdio> #include <string> #include <cstdlib> #include <GL/glut.h> using namespace std; void display(void); void polygon(int a, int b, int c , int d); void DrawCube(); int WindowHeight … | |
Re: On line 142 you are trying to assign something to getOwner. I don't see a variable called getOwner declared in function newg() or as a member of class ReversiGame, so that is likely where your problem lies. Dave | |
Re: You were on the right track by including sstream, but then you didn't use it! Long lists of code like this this: [code] if (IPd == ip0) { k = 0; f0.open ("Node0.txt"); f0 << "I received a packet from Node " << i << "\n"; // write all the … | |
Re: I would suggest keeping your questions and related code as short and sweet as possible. For example, in this case, all you want to know is how to tell how long a key has been held down for, correct? Unfortunately I don't know how to do that! (sorry) Dave | |
Re: If you want to use the enums in the other functions, they need to be global: [code] enum MAKERS {FORD,BMW,VOLVO,CHEVY,CADILLAC,HYUNDAI}; enum COLORS {RED,BROWN,BLACK,WHITE,GREY}; int main () { [/code] What are these lines supposed to do? [code] MAKERS = maker; COLORS = color; [/code] Here is a simple example of using … | |
Re: Can you describe what you did to figure it out since you marked the thread as solved? Dave | |
Re: I would get the whole line and then split it at the spaces. This is a pretty fancy way I found, but it works: [code] #include <iostream> #include <sstream> #include <string> #include <algorithm> #include <iterator> #include <vector> int main(int argc, char *argv[]) { std::string sentence = "hello world test 1 … | |
Re: You mean you want a user to login to your program? A simple string input and compare should do the trick, unless you are looking for something actually secure. You need to let us know more details about what you're trying to do. Dave | |
Re: I would do it like this: [code] std::ifstream fin(Filename.c_str()); if(fin == NULL) std::cout << "Cannot open file." << std::endl; std::vector<std::string> Lines; std::string line; while(getline(fin, line)) { Lines.push_back(line); } for(unsigned int i = 0; i < Lines.size(); i++) { std::cout << Lines[i] << std::endl; } [/code] Dave | |
Re: This doesn't really seem like a c++ question to me. Dave | |
Re: What command are you using to compile/link? What are the names of those files posted above? Is this the absolutely smallest code that will demonstrate your problem? Dave | |
Re: Can you please specify your problem a little bit better? Are there errors? What is the expected output vs the current output? | |
Re: I really recommend you try to narrow the problem down to a ~ 15 line demonstration of the problem that we can look at. You should use a debugger to step through the code until you reach the line that it is crashing on - code after that is certainly … | |
Re: 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 | |
Re: You should reply to the thread with the solution, instead of removing the question. If you delete the question, the answer doesn't help anyone in the future! Dave | |
Re: Since this is a c++ forum, I'll give a c++ example (I don't know anything about that extern c stuff!) main.cpp [code] #include "test.h" int main() { Test a; a.foo(); return 0; } [/code] test.h [code] #ifndef test_h #define test_h #include <iostream> class Test { public: void foo(); }; #endif … | |
Re: 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 | |
Re: I don't understand, if you know c++, this shouldn't be an issue at all... you pretty much just need to add some braces. Dave | |
Re: My suggestion is to not use OpenGL directly, but rather, use VTK! ([url]http://vtk.org/[/url]) I have been working hard for the last year writing examples, which you can find here: [url]http://www.vtk.org/Wiki/VTK/Examples[/url] There is certainly a learning curve (but there is with OpenGL, too, as you're experiencing), but it's much cleaner than … | |
Re: My main comment is that I would definitely use STL vectors instead of all of your arrays - the memory is managed automatically, you can do bounds checking if you wish (with .at() ), you do not need to know/guess the size ahead of time, you can resize them, and … | |
Re: Welcome to the forum. You need to close your code tag with '/code', instead of 'icode' for it to display properly. I recommend you do the following: Make as simple as an example as you can. Do not take input, but rather hard code some values. Make a 10 line … | |
Re: I use VNL (part of VXL: [url]http://vxl.sourceforge.net/[/url]) for my math operations: Here is the function you'd want: [url]http://www.lems.brown.edu/vision/vxl_doc/html/core/vnl/html/classvnl__matrix.html#f714bb239b2b1bdbea787b5920ae07f1[/url] | |
Is there a data structure that lets me push and pop things onto/off of a queue, but also doesn't allow duplicates? E.g. I want [code] queue a; a.push(1); a.push(2); a.push(2); a.push(3); [/code] to only have 3 elements, because 2 was added twice so the second time it is just ignored. … | |
Re: You could input a string instead of an int and then check if the string contains a '.'. | |
Re: A sample program? Or do your homework for you? | |
Re: I'd recommend using an std::vector to store you students. You'd want to use a set of if/else if statements or a switch statement to map the numerical grades to letter grades. Dave | |
Re: What do you need to do with them? For image processing, I use ITK ([url]http://itk.org/[/url]) or VIL (part of VXL : [url]http://vxl.sourceforge.net/[/url]). Dave | |
Re: Your code compiles fine on my machine. g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2) Dave | |
Re: Is this c++? I don't think [icode]ref class CSquare: Rectangle[/icode] or [icode]property int lt [/icode] are valid c++ statements. Dave | |
Re: Can you post a compilable snippet? I.e. you're Event class is missing. Dave |
The End.