159 Posted Topics
Re: You should delete the line because it makes no sense? What are you trying to do anyway? | |
Re: cout and endl are in the namespace std. so you either need to prepend std:: when you refer to them or add using namespace std;. | |
Re: Declare main as follows: [code]int main(int argc,char** argv) { ... }[/code] argc is the number of arguments, argv is an array with the arguments. The first argument is always the command line that was used to execute the program (without parameters), the rest are the actual parameters. | |
Re: I suppose that was supposed to be a mail to your students? | |
Re: See [url]http://www.cplusplus.com/reference/clibrary/csignal/signal/[/url] Note that in the case of a segmentation fault or division by zero all you can do in the signal handlers is to terminate the program in a controlled way, because when the signal handler exits, execution will be continued at the point where the problem occurred, which … | |
Re: Some comments that could help you with this and future projects: 1. It's better to declare variables as soon as they are needed (and not at the beginning of the function). That way, you don't have to scroll up to check what type the variable is and you don't have … | |
Re: It's not necessary to create your own split function, as boost has one and even foreach if you want. [code]#include <iostream> #include <string> #include <vector> #include <boost/algorithm/string.hpp> #include <boost/foreach.hpp> using namespace std; using namespace boost; #define foreach BOOST_FOREACH int main() { string s = "@This@Is@My@String@"; vector<string> parts; split(parts,s,is_any_of("@")); foreach(string& p,parts)cout … ![]() | |
![]() | Re: I'm not surprised you didn't get any help, since you never explained what the problem is. ![]() |
Re: It would really help if you could post the entire input file, that would allow us to debug the code and quickly find the remaining issues. Of course, it would save yourself a lot of time in the future if you just learn on how to use the debugger yourself. … | |
Re: This thread is nearly three years old, just saying. [QUOTE]int i,k=0,j; int a[3]; int b[3]; int c[6]; bool flag; //cout<< [/QUOTE] Uh? Sometimes I just don't get what people are thinking... | |
Re: [QUOTE=Nick Evan;1241871]First of all: Why? This sounds like you're making somesort of malware/spyware and that's against the rules.[/QUOTE] There would be no point for malware to do something like that.. | |
Re: You will need OS-specific functions to do that. I assume you're using Windows. For the cursor, there is GetCursorPos and SetCursorPos. If you want to simulate mouse clicks, you can use functions like SendInput or PostMessage. In any case, you'll spend much time studying on MSDN. | |
Re: -O3 goes without saying if you need to program to be fast. How a function object is supposed to speed up anything is beyond me, though. | |
Re: You should have a look at the functions srand and rand. | |
Re: My guess is that there are words in the file that are longer than the 7 chars that fit in Hex. Never use char arrays unless you know exactly what you're doing - use string instead. By the way, the code inside the for( int y=7;y>=0;y--) loop is unnecessarily redundant. … | |
Re: [code]const int arraySize=sizeof(Array)/sizeof(*Array); cout << Array[rand()%arraySize] << endl;[/code] | |
![]() | Re: That's most likely because the other computer has a different locale. For example, the same date might have to be specified as 01.01.2010 on that system. |
Re: And the other problem is that argv is declared as char*[1] instead of char**. | |
Re: I wrote this code many years ago and due to the less than stellar variable names it's hard to understand - but well, it works. [code]static bool PlaceHolderMatch(const char* QS,const char* MS,int QL,int ML,char Placeholder='?') { if (QL!=ML)return false; for (int i=0;i<QL;i++) { if (MS[i]==Placeholder)continue; if (MS[i]!=QS[i])return false; } return … | |
Re: Whenever you find a space, delete all spaces that come right after it. Deleting a character is done by moving all following characters one position down. | |
Re: The first problem is that you use char* instead of string. The second is that you're using getline wrong: [code]getline(file,black.day);[/code] | |
Re: There is no sense in storing all names in the same char array. What you're looking for is an array of strings. [code]string names[7]; for (int i=0;i<7;i++) { cin >> names[i]; }[/code] | |
Re: Aside from an intToStr function, you should also create yourself a leadingZeros function, which you'll probably want to use here. You'll need both very often, so it's a good idea to create a small library with such functions for private use. You can also use boost's lexical_cast instead of intToStr. | |
Re: Temporary objects aren't [i]strictly[/i] const. While they act const when trying to pass them to a function, you can still call non-const functions on them. Consider this: [code]class A { public: A() : num(0) {} void setToFive() {num=5;} int num; }; void setAToFive(A& a) { a.num=5; } int main() { … | |
Re: Look up srand and rand to generate random numbers. If you have ten different item types, generate a number between 0 and 9 and create the item matching that number. | |
Re: I see two problems: 1. You're using delete (instead of delete[]) on buf, even though the array was created with new[]. 2. In FileSystemDataStream::open you're returning an object created with new as a regular pointer (instead of auto_ptr) which opens the gates to the realm of potential double deletes and … | |
Re: Either the program is already running or you simply don't have write access to that directory. | |
Re: You seriously need to indent your code, then mistakes with extra or missing braces couldn't happen. | |
Re: I don't explicitly write this-> unless necessary. There is no point - it's a [i]considerable[/i] extra effort since most of the function code you write is inside one class or another. And there is no real benefit - the only reason you would need to write this-> is because you … | |
Re: "Define a new data type" means you're supposed to create a new class (or possibly three). | |
![]() | Re: And here's another. This will be many, many times faster if the file contains a lot of entries. [code]#include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <sstream> using namespace std; struct Foo { Foo() : quantity(0) {} Foo(const string& part,const string& a,const string& b,int quantity) : part(part), … ![]() |
Re: Use the debugger, it'll take just a minute to find the problem. Compile with g++ -g -o test test.cpp to include debug information, then run gdb test And enter the commands start, then continue. When it stops due to the segmentation fault, type "where". | |
Re: C&P from the other forum: [QUOTE]Yes, you can do this with MinGW. This was compiled using MinGW on Linux: [url]http://94.23.22.190/etc/voc.exe[/url] MinGW exists for the Mac too: [url]http://crossgcc.rts-software.org/doku.php[/url][/QUOTE] | |
Re: Function pointers are the way to go: [CODE]class button { public: button(void (*onClick)(button&)) : onClick(onClick) {} void click() {onClick(*this);} private: void (*onClick)(button&); }; void myOnClick(button& owner) { cout << "Button clicked!" << endl; } int main() { button myButton(myOnClick); myButton.click(); }[/CODE] If you don't want to use function pointers, you … | |
Re: I'd also like to point out that it's very bad style to declare counter variables outside the for loop, unless you actually need the value the loop stopped at. | |
Re: [QUOTE]then I need to pair every element of the 2nd column like this. C++ Syntax (Toggle Plain Text) 1. {(1,3),(1,5),(1,8),(1,9),(1,7),(1,10),(2,3).....} {(1,3),(1,5),(1,8),(1,9),(1,7),(1,10),(2,3).....} ie pairs are formed between elements only if their elements in the 1st row are different. [/QUOTE] Maybe you should explain this again. For example, why is (1,2) not … | |
Re: Why are you calling rand() twice on each line? That makes no sense. Besides, the code has nothing to do with your problem. And you might want to formulate an actual question, because I'm not sure what your problem exactly is. | |
Re: [CODE]struct matrix_2x2 { //interesting functions here double v[2][2]; };[/CODE]? | |
Re: You should look up the string class method substr, it does what you need. [CODE]string str="0092-123-1234567"; int cpos=0; while (cpos<str.length() && str[cpos]!='-')cpos++; if (cpos>=str.length())error(); //no '-' found string tail=str.substr(cpos+1,str.length()-cpos-1);[/CODE] | |
Re: string is included by iostream, so you can just omit the include and still use strings. | |
Re: You never defined getmem anywhere, so how can you expect it to work? | |
Re: In this case, using getline is appropriate: [CODE]ItemizedProductLine::ItemizedProductLine(ProductCode pc, double rrp, double sp, int oh, char* desc): ProductLine(pc, rrp, sp, oh, desc) { for (;;) { cout << "Please enter serial number:" << endl; string serial; getline(cin,serial); if (serial.empty())break; serialNumbers.insert(serial); } }[/CODE] | |
Re: Just check if all values in the resulting long array are within the value range of short. If so, you can transfer the data over to a short array. | |
Re: A glaring mistake I noticed when skimming the code is [code]float *real=new float[width*height]; real=convolve2D(data,gx_r,gy,filterHalfWidth); float *imaginary=new float[width*height]; imaginary=convolve2D(data,gx_i,gy,filterHalfWidth); [/code] You're requesting memory for real and imaginary, then immediately overwrite the pointer, creating a huge memory leak. And while I see an abundance of new[]s in other parts of your code, … | |
Re: This would defeat the purpose of libraries. When moving all code into header files, it would be included in all programs that use it, instead of separate .dll or .so files. When bugs are fixed in a library, you couldn't just replace the shared library - you would have to … | |
Re: To get the title of a window, you can use GetWindowText. You will need to acquire the target window's handle first. | |
Re: Just replace `pkg-config gtkmm-2.4 --cflags --libs` with its output manually. | |
Re: First off, using delete on a null pointer never throws and is perfectly okay. A SIGTRAP can indicate memory corruption or a double free. Remember that the memory corruption does not necessarily need to occur in Flob.cpp. You also should consequently use new and delete/delete[] in your programs to avoid … | |
Re: Problems I'm seeing: 1. I don't see size being initialized anywhere, so even the first call to Recv could crash the program due to trying to allocate ridiculous amounts of memory. 2. You are not checking the return value of recv to see whether the connection has been terminated. Perhaps … |
The End.