921 Posted Topics
Re: If all your trying to do is sort [B]int's[/B] / [B]floats[/B] you are doing it the hard way, all you have to do is convert each string you input to a float and then sort them. So you can delete the other two functions ([B]lrg[/B], [B]posd[/B]). Something thing you should … | |
Re: Well, dynamically allocating space is much slower than stack and the life of a dynamic variable is dependant on when you decide to delete it, however stack variables are deleted at the end of the code block. | |
Hi I have a small question, probably quite obvious but I cant seem to figure it out. When using the ifstream or any other stream you can tell if it was sucessfull in its last event. For example: [CODE=CPP] #include<fstream> int main() { ifstream in("test.txt", ios::in); if (in) { } … | |
Re: I learned how to do Win32 programming quite well in under a week off this tutorial, it might be what your looking for. You should also do this tutorial before moving on to MFC, it will help. [url]http://www.winprog.org/tutorial/start.html[/url] | |
Re: I think you need to disable unicode to remove those errors. Try adding: [CODE]#undef UNICODE[/CODE] at the very beginning of your source code. | |
Re: Can you post the code that is giving this error ? | |
Hi I am trying to make function which returns a substring as a [ICODE]char*[/ICODE], but [ICODE]string::substr[/ICODE] returns a [ICODE]const char*[/ICODE]. So I have managed to make a function that will return a substring as [ICODE]char*[/ICODE], except when I was comparing the speed of the two, I found that [ICODE]string::substr[/ICODE] was … | |
Re: You havent explained your problem. I can see a few errors just by looking at it. [LIST] [*][ICODE]BaseArea (i,x,y,z);[/ICODE] [B]i[/B] hasnt been assigned a value yet [*]Change <iostream.h> to <iostream> [*]Your using std events but you fergot to add [ICODE]using namespace std;[/ICODE] at the beginning of the code [/LIST] [B]<iostream.h> … | |
Re: Many problems in the code.. but this will remove the error: [CODE] #include <iostream> #include <vector> using namespace std; class Pair { public: Pair(int a, int b) {x=a; y=b;}; int get_x() {return x;}; int get_y() {return y;}; private: int x; int y;}; int main() {[COLOR="Red"]vector<Pair> set;[/COLOR] Pair* a1 = new … | |
Re: Yes, what Ancient Dragon sead will work fine, to save some time you could define it as a macro. [CODE] #include<iostream> #define rand_f(n) (((rand()%10000)/10000.0f)*n) int main() { for (int i = 0; i < 100; i++) { std::cout << rand_f(1) << '\n'; } std::cin.ignore(); return 0; } [/CODE] | |
Re: I dont often use goto, but it has been usefull in some cases for me too. There might be better ways to do this but this seems like the easiest method to me: [CODE=CPP] // Breaking out of nested loops for (int i = 0; i < 100; i++) { … | |
Re: No way.., the moniter doesn't communicate with the PC in any way, except by recieving information for it to display. | |
Re: Use code tags and format your code, then I will help. | |
Re: This will return true if the characters are equal up to the minimum length of the two strings. And it does not use the == operator. [CODE] bool Compare(char *str1, char *str2) { if (!(*str1 || *str2)) return true; // End of string bool match = (*str1 >= *str2) && … | |
Re: To make rand() generate a random number inbetween a certain value you need to do something like this: [CODE] int var = rand() % 100; // Generates a random number between 0 and 100 [/CODE] But every time you load the program up you should first call srand(time(NULL)); | |
Re: I think you need to learn how to use pointers. Heres a tutorial: You probably only need to look at the [B]Pointer initialization[/B] section. [url]http://www.cplusplus.com/doc/tutorial/pointers.html[/url] | |
Re: Very easy to do, heres an example: [CODE] #include<iostream> using namespace std; int main() { cout << "Enter maximum value: "; int max; cin >> max; // int sum = 0; // old1 + old2 int old1 = 0; // old int old2 = 1; // oldest // while (sum … | |
Re: [QUOTE] you cant have a single array of floats "mixed with" ints [/QUOTE] You can have an array with different data types, you just need to point to them using void* example: [CODE] void *array[] = {(int*)123, (char*)"Hello"}; cout << (int)array[0]; // prints 123 cout << (char*)array[1]; // prints "Hello" … | |
Re: I just happened to have posted in a thread very similar to this. [url]http://www.daniweb.com/forums/thread107523.html[/url] Heres a few functions that may help. [CODE] #include<iostream> using namespace std; inline char *SubStr(char *text, int beg, int end) { register unsigned len = end - beg; register char *cut = new char[len]; memcpy_s(cut,(rsize_t)len,&text[beg],(size_t)len); cut[len] … | |
Re: This may not be the best way to seperate each word, but heres how I managed it. You could read all the text out of the file first and then manually retrieve each word. [CODE] #include<iostream> using namespace std; #pragma warning(disable : 4018) char *SubStr(char *text, int beg, int end) … | |
Re: At the end of the code, try adding [CODE]cin.ignore()[/CODE] | |
Re: Try this: [CODE] #include <iostream> using namespace std; int main() { unsigned int digit1; unsigned int digit2; for( digit1 = 0; digit1 < 10; digit1++ ) { for( digit2 = 0; digit2 < digit1 + 1; digit2++ ) { cout << '*'; } cout << '\n'; } cin.get(); return 0; … | |
Re: The other computer you are testing it on probably does have the required .NET framework to execute the program. | |
Hello I have a friend who has a problem with his PC, as soon as he turns his computer on it will get stuck at the loading screen. The last line is displays is: [B]Press F1 for setup...[/B] He has the same problem before but it would continue normally after … | |
Re: For C you can use these functions: [CODE] #include<iostream> using namespace std; typedef unsigned char UCHAR; template<class t> inline char *toBase(t val, char base, char *values) { register char d = 1; t c; register bool _signed = val < 0; if (val >= 0) for (c = base; c … | |
Re: Heres a way of doing it without < > <= >= [CODE] #include<iostream> using namespace std; int min3(int a, int b, int c) { for (int i = 0;; i++) { if (i == a) return a; if (i == b) return b; if (i == c) return c; } … | |
Re: Here is a way to do it, I made a function [B]GetWord[/B] which will return a word depending on the index and the gaps you give it. It will loop through all the words and count number of words that match. Hope it helps. [CODE] #include<iostream> using namespace std; inline … | |
Re: Do you meen actually emulating keypresses ? Here is an example of how to do that: [CODE] #include<iostream> #include<windows.h> using namespace std; void SendKeysWait(char *text, int interval); int main() { system("start C:\\Windows\\notepad.exe"); Sleep(1000); SendKeysWait("Hello world!", 30); cin.ignore(); return 0; } void SendKeysWait(char *text, int interval) { int ch; int ch2 … | |
Re: It looks to me like the code you wrote never releases the click. This is how you fully emulate a mouse click: [CODE] mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left click mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // Right click [/CODE] | |
Re: can you just do [CODE]Form2->Text = "write something";[/CODE] | |
Re: I happened to have already made quite a few functions to help do this. for example: [CODE] GetWord(char *text, char *gaps, int bzIndex /* 0 based index */); cout << GetWord( "#[]Hello_{World::" , "#[]_{:" , 0); // Returns "Hello" cout << GetWord( "#[]Hello_{World::" , "#[]_{:" , 1); // Returns "World" … | |
Re: If you are using MSVC you can just add: [CODE]#pragma once[/CODE] at the start of your code. | |
Re: I see nothing wrong with the function isUpperCase except from what mitrmkar sead, it would not work if you passed the function the characters 'A' or 'Z'. | |
Re: This would have been very easy for you to test yourself, just made a quick test program: [CODE] int i = 5; cout << i++; // Still 5 [/CODE] [CODE] int i = 5; cout << ++i; // Now 6 [/CODE] | |
Re: It is also possible to do graphics in a console window but I dont know if it what you are looking for. You could easily use BitBlt instead of just LineTo but here is an example: [CODE] #define _WIN32_WINNT 0x0500 #include<windows.h> #include<iostream> using namespace std; int main() { HWND console … | |
Re: [QUOTE]Here's how to hide the console window[/QUOTE] You might have to add [CODE]#define _WIN32_WINNT 0x0500[/CODE] before you include the windows library to use the GetConsoleWindow() function. | |
Re: [QUOTE]You could also insert std::system("PAUSE"); between 18 and 19[/QUOTE] [url]http://www.gidnetwork.com/b-61.html[/url] | |
Re: This function converts a string to lowercase usering OR [CODE] char *ToLowerCase(char *text) { char *str = new char[strlen(text)]; register int i; for (i=0;text[i];i++) str[i] = text[i] >= 'A' && text[i] <= 'Z' ? text[i] | 32 : text[i]; str[i] = '\0'; return str; } [/CODE] | |
Re: [QUOTE]I'm not here for people to be asking me why at the last minute.[/QUOTE] Perhaps we wouldent if you didn't leave it to the last minute... If you had started this earlier and realized that you need help mabey some of us would be more inclined to help you. | |
Re: Try this. [CODE] template<class type> inline bool IsPrime(type val) { if (val==2)return 1; else if (val == 1) return 0; else if (val%2==0) return 0; register bool prime = 1; for (register type i = 3; i < val/2;i+=2) { if (!(val%i)) { prime = 0; break; } } return … | |
Re: btw, binary is spelt with 1 'n' :) heres my code: [CODE] #include<iostream> using namespace std; template<class t> inline char *toBase(t val, int base, char *values) { register char d = 1; t c; register bool _signed = val < 0; if(val >= 0) for (c = base; c <= … | |
Re: I learned C++ off "C++ A Beginner's Guide", its a very good book and it is probably what your looking for. [url]http://www.amazon.co.uk/Beginners-Guide-Second-Guides-McGraw-Hill/dp/0072232153[/url] | |
Re: Thats good if your just trying to print the values, but to actually convert between the different bases I think you have to make your own functions. I have already made them :) [CODE] #include<iostream> using namespace std; template<class t> inline char *toBase(t val, int base, char *values) { register … | |
Re: Ooooo, I made a game very similar to this in C++.. try it and see what score you can get. :) ![]() | |
Re: '0100' is not a string. "0100" is. Only use ' ' for single chars, use "" for strings; | |
Re: Im quite anoyed I named myself Williamhemswort by accident.. its actually ment to be WilliamHemsworth =) I might change it some day... |
The End.