1,247 Posted Topics

Member Avatar for littlestone

> which one is better? usually [ICODE]const char* const OUT_STRING = "hello world" ;[/ICODE] > why? more efficient. exception: you need to pass it often to functions which expect a [ICODE]const std::string&[/ICODE]

Member Avatar for vijayan121
0
61
Member Avatar for Rand al'Thor

> My thought was to make a .h file with a namespace. Would that work? yes, provided that all the functions in the header have internal linkage. ie. they are inline or put in an anonymous namespace (or have the deprecated static linkage specifier). and you have an include guard …

Member Avatar for Rand al'Thor
0
168
Member Avatar for Jennifer84

[code=c++]std::ifstream fin( "file1.txt" ) ; std::ofstream fout( "file2.txt" ) ; fin >> std::noskipws ; char ch ; while( fin >> ch ) { if( ch == '[' ) fout << 'x' ; fout << ch ; }[/code]

Member Avatar for Jennifer84
0
99
Member Avatar for manu1001

> CanvasObj class is defined as a template. Could that be a problem? yes, it is a problem. but it is solved easily enough. template typedefs are not legal in c++98. (they would be in c++0x) as of now, you can not write [code=c++] template< typename T > class CanvasObj …

Member Avatar for vijayan121
0
310
Member Avatar for Jennifer84

[code=c++] std::ifstream fin( "file1.txt" ) ; std::ofstream fout( "file2.txt" ) ; fout << fin.rdbuf() ; [/code]

Member Avatar for Jennifer84
0
73
Member Avatar for MasterDucky

> Im using rfind() to search backwards but for some reason it starts the search > from the beginning of the line and not from "pos" as i liked to [ICODE]rfind[/ICODE] does start the search from [ICODE]pos[/ICODE] as you expect. but it returns the position where the matching subsequence [COLOR="Red"]begins[/COLOR] …

Member Avatar for MasterDucky
0
139
Member Avatar for vesper967

[code] if( !word.empty() ) { if( word does not exist in tree ) { Node node(word, page); avl.insert(node); } else { Node* node = get the existing node for this word from avl node->incPages(page) ; } word = ""; } [/code] this part of the code is truly horrible [code]if(c …

Member Avatar for vijayan121
0
153
Member Avatar for sunrise2007

instead of this, [CODE]#include<string> using namespace std; #include<iostream.h> [COLOR="Red"]// no such header[/COLOR][/CODE] write [CODE]#include<string> #include<iostream>[COLOR="Red"] // the correct header[/COLOR] using namespace std; [COLOR="Red"]// moved down[/COLOR] [/CODE] also, [CODE]template <class TYPE, class KTYPE> bool List<TYPE, KTYPE> :: _search (NODE<TYPE> **pPre, NODE<TYPE> **pLoc,KTYPE key,KTYPE key1) { // Statements *pPre = NULL; *pLoc …

Member Avatar for zhelih
0
143
Member Avatar for USUAggie

> Do I just need to delete the individual parts of the array seperately? the array [ICODE]geometryArray [/ICODE]itself does not have a dynamic storage duration. (it was not allocated using [ICODE]new[][/ICODE]). therefore, [ICODE]delete [] geometryArray;[/ICODE] is an error. the contents of the array are pointers to objects allocated with a …

Member Avatar for vijayan121
0
103
Member Avatar for guest7

[ICODE]std::vector<int> row; std::vector<std::vector<int> > event(5,row); // note: every row is empty at this point for(lv = 0; lv < [COLOR="Red"]event.size()[/COLOR] ; ++lv ) { for( [COLOR="Red"]int gno=0 ; gno < event[lv].size(); ++gno[/COLOR] ) { // doing something // [COLOR="Red"]event[lv][gno] [/COLOR] } // ...[/ICODE]

Member Avatar for Joatmon
0
215
Member Avatar for ithelp

since the documents are html pages, you would need to remove the html formatting tags and all white space characters. (ie. just get the plain text of the document). this is required so that differences in fonts/character sizes/colours as well as differences in encoding of newlines etc. do not influence …

Member Avatar for vijayan121
0
87
Member Avatar for risa

> here my program crashes.............may be its bcoz the heap memory is less yes. to specify a larger process default heap size for your executable image, use the [ICODE]/HEAP[/ICODE] linker switch. [url]http://msdn2.microsoft.com/en-us/library/f90ybzkh.aspx[/url] to allocate 468 MB of memory, the heap is not a good choice. use [ICODE]VirtualAlloc[/ICODE] instead. [url]http://msdn2.microsoft.com/en-us/library/aa366887(VS.85).aspx[/url]

Member Avatar for risa
0
785
Member Avatar for theNewGuy1992

[url]http://www.guyrutenberg.com/2007/09/03/seeding-srand/[/url] [url]http://linux.die.net/man/3/srand[/url]

Member Avatar for vijayan121
0
163
Member Avatar for havec

> In java I can use "object" class, because "object" class is father class of all class. C programmers use [ICODE]void*[/ICODE] where java programmers use [ICODE]object[/ICODE]. you cannot use either without a cast; a wrong cast will result in unpleasant consequences in both. in C, incorrect runtime behaviour (seg fault …

Member Avatar for vijayan121
0
92
Member Avatar for Jennifer84

if you want to do some spirited programming ( [url]http://www.boost.org/libs/spirit/index.html[/url] ) [code=c++]#include <boost/spirit/core.hpp> #include <boost/spirit/actor.hpp> #include <iostream> #include <string> #include <vector> using namespace std; using namespace boost::spirit; bool parse_line( const char* cstr, vector<string>& words ) { subrule<0> top ; subrule<1> word ; return parse( cstr, // begin grammar ( top …

Member Avatar for Lerner
0
917
Member Avatar for Cyb3rAssasin

[url]http://msdn2.microsoft.com/en-us/library/ms997568.aspx[/url]

Member Avatar for vijayan121
0
89
Member Avatar for birdy_28

[code]int main() { // ... cout << "How many messages do you want to enter? "; cin >> size; array = new messages[size]; for (int i = 0; i < size; i++) { cout << "Message " << i+1 << ": "; [COLOR="Green"]//cin >> text;[/COLOR] [COLOR="Red"]getline( cin >> ws, text …

Member Avatar for vijayan121
0
86
Member Avatar for abarnett

you could also a. make the function const-correct b. use a size_t instead of an int for the size [code=c++]size_t smallestIndex( const int arr[], size_t size) { size_t smallestIndex=0; int temp=arr[0]; for(size_t i=1;i<size;i++) { if(arr[i]<temp) { smallestIndex = i; temp=arr[i]; } } return smallestIndex; }[/code]

Member Avatar for highspeedhook
0
3K
Member Avatar for Joatmon

[code]void SnakeSeg::kill() { if (alive) { alive = false; erase(); links = 0; if (next) { delete next; [COLOR="Red"]next = 0 ; // isn't this required?[/COLOR] } } }[/code]

Member Avatar for Joatmon
0
118
Member Avatar for mhilleleonhart
Member Avatar for sarehu
0
61
Member Avatar for kiwihaha

when you write a program, you express C source files as text lines containing characters from the source character set. when a program executes in the target environment, it uses characters from the target character set. these character sets are related, but need not have the same encoding. this is …

Member Avatar for Ancient Dragon
0
2K
Member Avatar for hockeyplayer051

you could also use [ICODE]basic_string<>::find_first_not_of[/ICODE] and [ICODE]basic_string::find_last_not_of[/ICODE] to locate the characters at either end that are illegal in an email address. and the use [ICODE]basic_string<>::substr[/ICODE] to extract the email address.

Member Avatar for vijayan121
0
119
Member Avatar for renatoguga

or you could use the non-viral [I]libcurl[/I]. [url]http://curl.haxx.se/libcurl/[/url] [code=c++]#include <curl/curl.h> #include <iostream> #include <algorithm> #include <iterator> struct stats { stats() : bytes_recd(0), ncalls(0) {} int bytes_recd ; int ncalls ; }; size_t on_data( void* buffer, size_t size, size_t nmemb, void* pv ) { size_t nbytes = size * nmemb ; …

Member Avatar for vijayan121
0
119
Member Avatar for veronicak5678

> How do I pass a file or filename to a constructor? write a constructor that takes a file name as the argument. > And how do I retrieve "word_list" if I can't return from a constructor? let the constructor store the words in a member variable. and provide an …

Member Avatar for vijayan121
0
112
Member Avatar for cosmos22

> ... develop a program that hides program files that should be kept out of sight in order to prevent them deleting any important files. what right do you have to try to prevent users from deleting files on *their* computers? to protect users from accidental deletion or overwrite, set …

Member Avatar for mitrmkar
0
184
Member Avatar for Quakes

> printing out the values to make sure they are correct they now look like this ... the initial default precision for a stream is 6. to print out more decimal digits, do something like [CODE]std::cout << std::fixed << std::setprecision(8) // 8 digits *after* decimal point << value ; [/CODE] …

Member Avatar for Quakes
0
91
Member Avatar for Hockeyfreak889

> VB will teach you a lot of things that are common to nearly all languages, > such as data types (integers, strings etc), loops, and file systems true. perhaps you could learn a language which is radically different from the mainstream ones (which are all alike in many respects). …

Member Avatar for Hockeyfreak889
0
169
Member Avatar for birdy_28

#include <iostream> #include <string> using namespace std; // identifier messages causes a name clash with the facet // because of the using directive (using namespace std) struct message_t { string message; int hours; int minutes; int seconds; }; int main() { int size; message_t* array; cout << "How many numbers?"; …

Member Avatar for vijayan121
0
113
Member Avatar for Infeligo

all literals (including literal strings) are immutable. they are [B]const[/B]. and therefore cannot be sorted (or modified in any way) [code]//char* a = "acbacb"; // bad programming practice [COLOR="Red"]const[/COLOR] char* a = "acbacb"; // the correct way char b[] = "acbacb"; // also ok. a literal can be used to …

Member Avatar for vijayan121
0
133
Member Avatar for andyg55

> Basically, 2 numbers are randomly generated, and are added together > to put in the variable 'result'. ...What I want to do is store every value and > take an average at the end, to get an average of the results it gives me. using [ICODE]rand()[/ICODE], each pseudo random …

Member Avatar for vijayan121
0
193
Member Avatar for hockeyplayer051

not really. try 1.0, 2.0, 3.0, 4.0, 10.0 what is required is the number with the ordinal rank of 3. using if as the *only* (control) statement? here's how you could do it for three integer numbers. [code=c++]#include <iostream> #include <algorithm> int main() { int lowest, /*low,*/ middle, /*high,*/ highest …

Member Avatar for Ancient Dragon
0
97
Member Avatar for sgw

you can't deactivate precision control. the precision is initially 6 and is always used for floating point (and never for any other type). so you could either make [ICODE]angle[/ICODE] an [ICODE]int[/ICODE] you can also write [code]cout << "sin(" << angle << ") = " << fixed << showpoint << setprecision(4) …

Member Avatar for sgw
0
13K
Member Avatar for vankdar

well, if you just need to count the number of words that end in punctuation, you do not need to store it in an array or a vector first. assuming that words are whitespace separated, read word by word into a [B]std::string[/B] till there is nothing more. [code]std::string word ; …

Member Avatar for atish00
0
101
Member Avatar for Jennifer84

JIT Debugging is an abbreviation for just-in-time debugging. all that it does is allow a debugger to be attched to a process which was not running under a debugger so far. see [url]http://msdn2.microsoft.com/en-us/library/ms679295(VS.85).aspx[/url] > some system file on the computer will take care of this Exception. no one will take …

Member Avatar for vijayan121
0
75
Member Avatar for Infeligo

this is not a valid c++ program (size of a c-style array must be a constant known at compile time). [code=c++]int main() { // ... int row_size = 1 ; // ... int new_row[row_size*4] ; // error: ISO C++ forbids // variable-size array 'new_row' // ... }[/code] this is (size …

Member Avatar for vijayan121
0
244
Member Avatar for henpecked1

[code]void gettemps(int temp[], int numtemp) { int count = 0; while (count != numtemp) { cout << " Enter " << count << " :00 " << " temperature "<< endl; cin >> temp[COLOR="Red"][count][/COLOR] ; if (temp[COLOR="Red"][count][/COLOR] >= -51 && temp[COLOR="Red"][count][/COLOR] <= 131) { hourlytemps[count] = temp[COLOR="Red"][count][/COLOR]; count ++; } …

Member Avatar for henpecked1
0
229
Member Avatar for teddyzhai

> easy to learn, light -weight... TinyXml++ perhaps? [url]http://code.google.com/p/ticpp/[/url]

Member Avatar for teddyzhai
0
162
Member Avatar for sonygamer

[QUOTE=hammerhead;548015] [code=c++]int eig( int num ) { if( num<10 ) return num; else return eig( eig( num/10 ) + (num%10) ) ; }[/code][/QUOTE] cool! though you spoiled it by [ICODE]void main()[/ICODE] and [ICODE]#include<iostream.h>[/ICODE]

Member Avatar for Lerner
0
335
Member Avatar for blcase

the c++ standard only specifies the performance requirements: for insert, erase and find this is [B]O( log N )[/B]. to meet this requirement, any tree implementation must be (reasonably) balanced at all times.

Member Avatar for vijayan121
0
79
Member Avatar for IIMarckus

[code=c++]#include <iostream> #include <iomanip> int main() { // std::cout << std::setiosflags(std::ios::fixed) // << 22.6 << '\n' ; std::cout << std::fixed << 22.6 << '\n' ; // easier // std::cout << std::setiosflags(std::ios::hex) // << 34 << '\n' ; std::cout << std::hex << 34 << '\n' ; // easier }[/code]

Member Avatar for vijayan121
0
111
Member Avatar for RockClimber

> So, if the user inputs 1234 for num, can I make a structure > where the name equals the value of num, i.e. Serialnumber 1234? 1234 is not a valid C++ identifier. but ven for a valid identifier ( like sn_1234 ), [B]the short answer to your question is …

Member Avatar for codeaa
0
101
Member Avatar for jrkeller27

> What type of syntax do I need to set my class to be of type comparable? nothing at all; just declare and implement the comparison operator(s). in [code] template<class Comparable> class BinarySearchTree; [/code] Comparable is just a place holder; the above is equivalent to [code] template< class T > …

Member Avatar for vijayan121
0
3K
Member Avatar for Jennifer84

it would be easier (and also more efficient) if you use a cliext::vector<> instead of a std::vector<> note: requires VC++ 9 (2008) [CODE]#include <cliext/vector> using namespace cliext ; // ... { // ... vector< String^ >^ vec = gcnew vector< String^ > ; vec->push_back( comboBox1->SelectedItem->ToString() ) ; String^ Box1 = …

Member Avatar for Jennifer84
0
173
Member Avatar for Ryuji5864

> The error message probably means that you should have a statement of some sort between each if and each else. >> No it doesn't. It is legal to have nothing in the TRUE position of an if yes, it does. having nothing is not legal C++. however, the statement …

Member Avatar for Ryuji5864
0
175
Member Avatar for nsoni

> What i expect after restore a network connection it should work proper the problem is that the FILE structure that is being passed to fprintf is no longer usable. it contains an operating system file descriptor (handle) which is not valid any more. you really do not need to …

Member Avatar for Ancient Dragon
0
147
Member Avatar for Jboy05

> How do I write three different calling statement to the MyFunction function > without declaring additional variable. what kind of question is this? the second parameter must be [B]I[/B]. there are an infinite number of ways in which the first parameter could be a bool. [CODE]MyFunction ( B, I …

Member Avatar for Jboy05
0
100
Member Avatar for jesseb07

the file is not in a good state after your loop executes [ICODE]file.eof() == true[/ICODE] clear the eofbit first. [CODE] file.clear() ; file.seekg( 0, std::ios::beg ) ; [/CODE] the seekg you are doing is ok because you are seeking to the beginning of the file. for a seekg to some …

Member Avatar for jesseb07
0
6K
Member Avatar for Jboy05
Member Avatar for Google Spider

> what should be coming next in this list > Hello world>>data types>>conditional execution>>C-style arrays>>C-style > strings>>loops>>functions>>structs>>classes templates, perhaps? > That book is very costly, and not available in any library near me Thinking in C++ 2nd Edition by Bruce Eckel is pretty ok and is available as a free …

Member Avatar for codeaa
0
159
Member Avatar for cosmos22

> How would I go about locating a file on the computer, and using it in my application? no really portable way of doing it (if you want a fast search). you could do this on unix [ICODE]system( "/usr/bin/locate 'file_name_glob' > files_found.txt" ) ;[/ICODE] and then pickup the complete path(s) …

Member Avatar for vijayan121
0
109

The End.