1,171 Posted Topics
Hi, When you post a new code snippet, it is always announced multiple times on Daniweb's index page, is this normal or is this just an unreported bug? | |
Re: Why do you use old-style header for the [B]math[/B] library? [ICODE]#include <math.h>[/ICODE] in C++, the new-style headers are preferred: [ICODE]#include <cmath>[/ICODE] :P | |
Re: Is it so difficult to post using code tags? It's nearly mentioned everywhere: in the forum announcement which you didn't read, on the background of the text box where you type in your message when making a post, above the forum announcements, in the '[URL="http://www.daniweb.com/forums/thread78223.html"]Read this [B]before[/B] posting[/URL]'. | |
Re: [QUOTE]1. When passing objects between each other is it preffered to use references if not what then? 5. When allocating resources should you always do it inside of a class?[/QUOTE] To answer your first question: yes, the preferred way of passing objects is [I]pass by reference[/I] In your fifth question … | |
Re: Just get the ASCII codes from the file (as a number), then put it in a char-variable and print it to the screen or append it at the end of the string variable where you want to put the converted string in :) | |
Re: Don't use [ICODE][B]!inf.eof()[/B][/ICODE] as a condition in a loop for reading a whole file: [CODE] void get_graph ( string const &filename, NodeMap &node_map ) { ifstream inf ( filename.c_str() ); string from, to; double weight; while ( [B]!inf.eof()[/B] ) { inf >> from >> to >> weight; if ( inf.good() … | |
Re: Start with these: [LIST] [*][URL="http://www.daniweb.com/forums/announcement8-3.html"]Forum Announcement[/URL] [*][URL="http://www.daniweb.com/forums/thread78223.html"]Read this [B]before[/B] posting[/URL] [/LIST] Then you should explain what you mean with: [I]...output should be in alphabetical order...[/I] (give an example) Do you mean the following? [CODE][U]File looks like:[/U] [I]lalal nn[/I] [U]Output should be:[/U] [I]aalllnn[/I][/CODE] | |
Re: Or read the following (IMO the best) free e-book about C++ programming: [URL="http://msdn.microsoft.com/en-us/beginner/cc305129.aspx"]http://msdn.microsoft.com/en-us/beginner/cc305129.aspx[/URL] :) | |
Re: What do you think of: [ICODE]cin >> [I]your_command[/I] >> [I]your_integer_parameter[/I];[/ICODE] ? | |
Re: [QUOTE=richymac;872680]im trying to write a cg pixel shader and just want to generate a random number too offset the colour of a pixel is there something i need to include, i tried using rand() but gave me errors thanks in advance[/QUOTE] [B]rand()[/B] and [B]RAND_MAX[/B] are both defined in [B]cstdlib[/B], so … | |
Re: How I would do it: [LIST=1] [*]Create a temporary variable of the same length as the one were you want to delete the spaces from [*]Use a for-loop to loop through the whole string where you want to delete the spaces from, every time you check whether the read character … | |
Re: [QUOTE=gsingh2011;875232]How would I make a program that can insert text into a text field in another program? Or click a button in another program?[/QUOTE] You could implement your application as one which communicates with it's own instances over a network, then you can let your program send messages to the … | |
Re: [QUOTE=kimbirdy09;875766]ok so could you give me some ideas/examples please, am really struggling with this part Thanks[/QUOTE] Take a look at the following: [LIST] [*][URL="http://www.daniweb.com/forums/announcement9-3.html"]Forum announcement[/URL] [*][URL="http://www.daniweb.com/forums/thread78223.html"]Read this [B]before[/B] posting[/URL] [/LIST] >Push it and put your code inside it. Use different code tags for each of your classes Or just paste … | |
Re: Does [B]Input.txt[/B] exist? (remember that it's case sensitive) Replace this (line 26-30): [CODE] while(!Input.eof()) { getline(Input, Line); cout << Line << endl; }[/CODE] with this: [CODE] while(getline(Input, Line)) cout << Line << endl; [/CODE] or this: [CODE] getline(Input, Line); while(!Input.eof()) { getline(Input, Line); cout << Line << endl; }[/CODE] | |
Re: [QUOTE=Mr Bin;875845]I will try. because I am a Vietnamese, so be able to write non-standard English. You please guess.[/QUOTE] We don't care about the fact whether English is your native language or not(*), it's [B]your effort[/B] which counts ! Let me clarify this: You have posted your assignment, but what … | |
Re: Here's an example on how to get the time: I don't know whether it's good to recommend you, but you can also achieve the same by using [B]scanf[/B] from the standard C library ([B]cstdio[/B]): [CODE] int hours, minutes, seconds; scanf("%d%*c%d%*c%d", &hours, &minutes, &seconds); [/CODE] or you could rewrite it in … | |
Re: [QUOTE=Luckychap;874631]Very common mistake in for loop: [code='c'] for(i=0; inputDone == 'y'; i++) [/code] did u get this!![/QUOTE] Don't blame him for making a mistake, everyone makes mistakes (me too), let me explain: If you write [ICODE]for(i=0; inputDone [B][COLOR="Red"]=[/COLOR][/B] 'y'; i++)[/ICODE] with one '=' sign then you're doing an assignment to … | |
Re: [QUOTE=tonig_ccc;874644]i wanted to ask you guys for some help i use microsoft visual studio 9.0 and i have downloaded hotspotter but it resulted it was all a source now i dont know how to compile it with mocrosoft visual studio any help???????????[/QUOTE] You could start by giving us the link … | |
Re: [QUOTE=nanchuangyeyu;874570]Hi, I am trying to declare a 3D array with the size of 6,400 and 400 in each dimension using the code as following: [CODE] short matrix[6][400][400]; [/CODE] So what's wrong with this code?[/QUOTE] Nothing, with me it compiles and runs fine :) Try compiling it as a [B]release[/B] executable, … | |
Re: [ICODE]#include <stdlib.h>[/ICODE] is old style C++, if your compiler supports it you should consider using the new-style header file: [ICODE]#include <cstdlib>[/ICODE] BTW, Read the third remark in my signature :P | |
Re: Did you define MIRACLES? [ICODE]#define MIRACLES 1[/ICODE] :P | |
Re: So, you want to convert a character string to an integer variable, try [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/"]atoi[/URL] ! example: [CODE] char num[] = "5269"; int i; i = atoi(num); // integer variable i now holds the number 5269 [/CODE] | |
Re: >Alternatively, is there a way to convert from string to char * (not convert from string to const char *, as c_str() does)? Yes there is: [CODE=C++] string s1 = "Hello World"; char *s2 = new char[s1.size()+1]; strcpy(s2, s1.c_str()); delete s2; [/CODE] explanation of the code: [CODE] line 1: declare … | |
Re: Is reviving a thread like this one really a good idea? I don't think so :( the first post is at least six years ago :P Edit:: I just see that the posts are moved to a new thread, so all what's above in this post doesn't apply anymore :) | |
Re: I would suggest you to go to your local bookstore and buy that one :) (both books are exactly the same, I compared the ISBN code) | |
Re: [ICODE]int count = 1;[/ICODE], you should declare it outside your while-loop :) | |
Re: If you only want to convert integers to a string, then you should try [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/"]itoa[/URL] :) | |
Re: First some remarks on your code: [CODE] while(!soubor.eof()) { getline(soubor,radka); if(soubor.eof()) break; . . . [/CODE] can be replaced by: [CODE] while(getline(soubor,radka)) { . . . [/CODE] and [ICODE]while (pch != NULL)[/ICODE] is actually the same as [ICODE]while (pch)[/ICODE] :P Is the matrix always of the same dimension? | |
Re: [CODE=C++] ages[0]='1'; ages[1]='2'; ages[2]='3'; ages[3]='4'; [/CODE] won't put the numbers 1, 2, 3 and 4 in the array :) You'll have to write [CODE=C++] ages[0]=1; ages[1]=2; ages[2]=3; ages[3]=4; [/CODE] Or you can truncate it by directly initializing the array: [ICODE]int ages[4] = {1,2,3,4};[/ICODE] [ICODE]while (ages[4] != 1,2,3,4);[/ICODE] should be: [ICODE]while … | |
Re: Take a look at the following example: [CODE=C] #include <stdio.h> void print_el(char **p, int el) { printf("%s\n", p[el]); } int main(void) { char *blah[] = { "string1", "string2" }; print_el(blah, 1); print_el(blah, 0); return 0; } [/CODE] output is: [CODE] string2 string1 [/CODE] >how can I move to the next … | |
Re: [QUOTE=Dave Sinkula;872343][code]6.8.5 Iteration statements Syntax iteration-statement: while ( [COLOR="Red"]expression[/COLOR] ) statement do statement while ( expression ) ; for ( expressionopt ; expressionopt ; expressionopt ) statement for ( declaration [COLOR="Red"]expressionopt[/COLOR] ; expressionopt ) statement[/code][/QUOTE] According to the C++ standard it's: [CODE] [U]6.5 Iteration Statements[/U] iteration-statement: while ( [COLOR="Green"]condition[/COLOR] ) … | |
Re: [QUOTE=Arumugams;872879]Hi, I am new for writing plugins.Dont know how to start.Can any body provide link or sample codes for plugins.[/QUOTE] Google on [B]Browser Helper Objects[/B] :) | |
Re: [QUOTE=amrith92;872827]Do you mean STL's [ICODE]std::stack[/ICODE], or something of your own creation?[/QUOTE] As he's talking about iterators, I assume he means the stack template from STL :) | |
Re: Hi, mate, this forum isn't made for 'testing' how your image is displayed :angry: !! By the way, you even don't have a question and this thread isn't Java related ! | |
Re: [ICODE]for($i = 86400; $i < 604900; [COLOR="Red"][B]$i + 86400[/B][/COLOR])[/ICODE] has to be [ICODE]for($i = 86400; $i < 604900; $i +[B][COLOR="Green"]=[/COLOR][/B] 86400)[/ICODE] (otherwise your loop index always stays [B]86400[/B] :)) :P | |
Re: Take a look at [URL="http://www.daniweb.com/code/snippet1179.html"]this[/URL] code snippet :) Or you could use a vector. | |
Re: Did you select 'C Project' in the 'New Project' Dialog ? Otherwise reinstalling Dec-C++ might solve the problem :) | |
Re: [QUOTE=adatapost;872278]tux4life >Unportable rubbish which doesn't work. adatapost>Oh!!! Buddy you should have to test this code before judge.[/QUOTE] I have tested it before I judged, I'm not stupid ... | |
Re: A [U]condition[/U] is something which is brought down to be [ICODE]true[/ICODE] or [ICODE]false[/ICODE]. Most of the time, an [U]expression[/U] can be evaluated to be [ICODE]true[/ICODE] or [ICODE]false[/ICODE], [ICODE]false[/ICODE] stands for the value [ICODE]0[/ICODE] and [ICODE]true[/ICODE] stands for all the other possible values :) | |
Re: If you program in assembler, knowledge of a high-level/middle-level programming language is already assumed before you even start learning assembly, and you don't know how a simple loop works in Java? :P If your question is how to do this in assembly, you should have posted/started this thread in the … | |
Re: You can use a [B]struct[/B] in practically (this means: in most cases, but not always) the same way as a [B]class[/B] (because technically structs are classes in C++), consider the following example: [CODE] [B][COLOR="Green"]struct[/COLOR][/B] s { void disp(); s(int num); [COLOR="Green"][B]private:[/B][/COLOR] int n; }; s::s(int num) { n = num; … | |
Re: It would be helpful to me if you posted the whole code (using code tags) you were trying to compile (if your question isn't already solved yet) ... Probably you forgot to type a ';' somewhere in your code :) | |
Re: If your whole class, including all your class' function declarations looks like this: [CODE] [COLOR="Green"]class A { int n; public: A::A(int num); void disp_num(); };[/COLOR] A::A(int num) { n = num; } void disp_num() { std::cout << "n = " << n << std::endl; } [/CODE] Then you'll have to … | |
Re: [QUOTE=amrith92;871565]If you had compiled this on a new compiler, then this would surely have thrown an error, wouldn't it?[/QUOTE] Nope, I can compile it using the newest MinGW compiler :) (BTW, If there's need for a Borland-style conio implementation for MinGW, you can always find it [URL="http://conio.sourceforge.net/"]here[/URL]) Regarding to the … | |
Re: >Should I have to switch to other IDE? The IDE you're using doesn't define the programming language (C++), so the answer is no :) | |
Re: Write and compile it as a Windows program (without a window), you could use the [ICODE]fstream[/ICODE] classes for file I/O :) | |
Re: Can you please post your whole code? It's easier for me to find the error then :P | |
Re: Try compiling with:[ICODE]g++ fig03_17.cpp Gradebook.cpp[/ICODE] :) | |
Re: [U]Example of a structure:[/U] [CODE] struct book { char title[25]; char author[25]; char publisher[25]; int price; }; [/CODE] [U] Example of an enum(eration):[/U] [CODE] enum book { BIG, SMALL, }; [/CODE] | |
Re: Can you please post the code you're trying to compile? |
The End.