1,247 Posted Topics
Re: placement new is used when you do not want operator new to allocate memory (you have pre-allocated it and you want to place the object there), but you do want the object to be constructed. examples of typical situations where this may be required are a. you want to create … | |
Re: u could [code] std::set<int> unique_ints ; // N == number of elements // MAX_VALUE == max value of an element while( unique_ints.size() < N ) unique_ints.insert( std::rand()%MAX_VALUE ) ; //iterate from unique_ints.begin() to // unique_ints.end() and populate the array [/code] | |
Re: > start quote: const int SIZE = 10; double **arr = (double**)malloc(SIZE * sizeof(*arr)); for(int i = 0; i < SIZE; ++i) { arr[i] = (double*)malloc(SIZE * sizeof(*arr[0])); } } > end quote. This is first allocating an array of pointers, and allocating memory one by one for each one … | |
Re: if performance is not of great concern, you could do one of the following: [B]a.[/B] when you add an item to the array, [B]1.[/B] add it as the last element. [B]2.[/B] compare it with the element just ahead of it; if it has a higher priority, swap the two. [B]3.[/B] … | |
Re: [quote=winbatch;344733]Is there a way using file handling functions to search within a text file to find the position of certain text WITHOUT having to read each character/line and evaluating it?[/quote] the short answer is no. but you may not have to do this; let the standard library do the work. … | |
Re: [quote=Ancient Dragon;344493]>>Extract the lower 4 digits of the result produced by step 2. The easy way is to convert the number to a string then only use the last 4 digits. [code] int num = 12347; char buf[10]; sprintf(buf,"%d",num); int seed = atoi( &buf[1] ); [/code][/quote] The easier way is … | |
Re: [quote=avi_new;344494]All the errors are from these codes. I have no clue why? Thanks in advance. [code=C++]std::map<std::string, std::map<std::string, c_PerformanceMeasurement> >::iterator iClass = mPerformances.find(Class);[/code] [code]if (iClass != mPerformances.end()) { std::map<std::string, c_PerformanceMeasurement>::iterator iPerformance = iClass->second.find(Name); if (iPerformance != iClass->second.end()) { return iPerformance->second; } }[/code][/quote] looks like the variable [B]mPerformances[/B] is a [B]const map<...[/B] … | |
Re: [code] #include <fstream> #include <iterator> #include <algorithm> using namespace std; struct copy_file_to_stream_t { explicit copy_file_to_stream_t( ostream& s ) : stm(s) {} void operator()( char* file_name ) const { ifstream file(file_name) ; file >> noskipws ; istream_iterator<char> begin(file), end ; copy( begin, end, ostream_iterator<char>(stm) ) ; } ostream& stm ; }; … | |
Re: make your operator< const correct. [code][COLOR=#000000] bool Node::[/COLOR][COLOR=#000000]operator< ( const Node&) const [/COLOR][/code] | |
Re: try: a. [url]http://www.symbian.com/developer/techlib/v8.1adocs/doc_source/N10012/index.html[/url] b. [url]http://www.symbiantutorial.org/en/space/start[/url] | |
Re: a. read one line b. strip off unwanted chars (non-printable/whitespace/,) c. analyze the remaining chars. repeat a,b,c till end of file. [code] struct is_2b_thrown_away { bool operator() ( char ch ) const { return !isprint(ch) || isspace(ch) || (ch==',') ; } }; void process_file( const char* file_name ) { ifstream … | |
Re: the label [B]menu: [/B](line 28) hides the variable [B]char menu [/B](line 12). you could use the scope resolution operator ([B]::menu[/B]) to make the error go away; but hiding names like this is not a good idea. technically, a label is a pointer (address). | |
Re: [quote=jasssvj;342587]Hi! How can I read all files in a directory, when I don't know which files are there? Sincerely Jasmina Jeleva![/quote] you could use the boost filesystem library. it is portable across unix, linux and windows. here is a sample program which prints the names of all files in a … | |
Re: [quote=Infarction;342205]Some people have argued that ++i yields more efficient assembly code. When I checked, they were the same. In this situation, it doesn't matter.[/quote] in this specific case it really does not matter. When applied to primitives such as int or char, they are indistinguishable in terms of efficiency. When … | |
Re: see: [url]http://msdn2.microsoft.com/en-us/library/aa378184.aspx[/url] | |
Re: socket++ is a library that i have used. it works resonably well. it has a distinct c++ feel about it; sockets in the library have the same interface as the streams in the iostream library. here is the link: [url]http://www.linuxhacker.at/socketxx[/url] [URL="http://freshmeat.net/projects/socketxx/"] [/URL] | |
Re: [quote=student86;341560]I need help verifing. [COLOR=#000000]...... Create a new function to verify the numeric input values. This function will be in a separate source file. [/COLOR] [B][B][COLOR=#000000]verifyValue.cpp[/COLOR][/B][/B] [COLOR=#000000]This function will determine if a string contains a valid numeric value. It will return true or false. [/COLOR][/quote] [code] bool verify_value( const char* … | |
Re: try [code] int a[16] = { 0 }, b[16] = { 0 } ; b[16] = 25 ; printf( "%p -> %d %p -> %d\n", a, a[0], b, b[0] ) ; [/code] notes a. an all hw architectures that i know of, the stack grows from higher towards lower addresses. … | |
Re: a. read each line in the file into a std::string b. parse the line that was read using a std::istringstream [code] enum { MAX_ITEMS_PER_LINE = 25 }; ifstream file("file_name - perhaps picked up from argv[1]") ; string line ; while( getline( file, line ) ) { istringstream stm(line) ; int … | |
Re: [quote=Salem;340436]> You cannot use C to solve this problem. Of course you can, it just takes an additional library to help you do all the hard stuff. [URL]http://gmplib.org/[/URL] Or if you're only interested in a couple of math ops, then you could work out how to do long arithmetic in … | |
Re: [quote=tasomaniac;339848]I am a student in Bogazici University/Turkey. We have a project and I want to change the cursor position but there is a problem. Our teachers are using Microsoft Visual C++ 2005 Express Edition. In this compiler there is no windows.h header. What can I do?[/quote] visual c++ express does … | |
Re: [B]getc_unlocked()[/B] and [B]getchar_unlocked()[/B] functions conform to IEEE Std 1003.1-2001 (POSIX.1). so every *nix (mac is *nix below the hood) should have them as part of the base system. (in linux, it would be in glibc.) "[B]getc_unlocked()[/B] and [B]getchar_unlocked()[/B][B] [/B]functions are equivalent to [B]getc()[/B] & [B]getchar()[/B] respectively, except that the caller … | |
Re: you need the framework for the IDE. the compiler itself (and link etc.) do not. if you are willing to work from the command line using cl.exe, link.exe, nmake.exe, you do not neet the framework. | |
Re: the parser for the command line seperates arguments by looking for whitespaces. so if the command line parameters do not have whitespaces in them thins work fine. putting quotes indicates that everything inside the quotes, including white spaces are part of the single arg. since argv[0] is [B]the full path[/B] … | |
Re: this is what the linux man pages say (in part) about rand(3): " ... The versions of [B]rand()[/B] and [B]srand()[/B] in the Linux C Library use the same random number generator as [B]random()[/B] and [B]sranÂ[/B] [B]dom()[/B], so the lower-order bits should be as random as the higher-order bits. However, on … | |
Re: char temp[length]; the error is that length is not a constant known at compile-time. (this is not an error in C99, but is an error in standard C.) | |
Re: comparing a signed value with an unsigned value has a logical problem. [code] int si = -7 ; unsigned int ui = 68 ; ( si < ui ) ; // true if interpreted as si < signed(ui) // false if interpreted as unsigned(si) < ui [/code] at the very … | |
Re: [quote] oh... and no other database format to my knowledge allows for multimedia, or files in general to be stored within a field, which is the purpose for designing this structure. If i am wrong PLEASE let me know. [/quote] you mean no other open source database. this is what … | |
Re: you forgot to terminate the definition of the class with a [B]; [code] [/B]class __gc whatever { } // need a semicolon here [/code] | |
Re: a. read the lines and insert it into a vector [code] ifstream file("customer.txt") ; string rec ; vector<string> records ; while( getline(file,rec) ) records.push_back(rec) ; [/code] b. iterate over the vector backwards to access the redords in reverse order [code] ofstream outfile("custFileCopy.txt") ; std::copy( records.rbegin(), records.rend(), std::ostream_iterator<string>(outfile) ); [/code] you … | |
Re: another possibility is that the variable or function is defined in more than one file. in this case your error message would look like 'multiple definition of <identifier>' or 'one or more multiply defined symbols' if you tried to declare a variable in another file [code] extern int first = … | |
Re: there are two ways to simulate returning many values from a function: a. return a [B]struct [/B]with more than one member variable. std :: pair<> is handy if you want to return a pair of values. b. pass a modifiable referance (or pointer to non const) as a parameter, which … | |
Re: see: [url]http://msdn2.microsoft.com/en-us/library/ms682586.aspx[/url] | |
Re: since we are using std::string, why not [code] #include <iostream> #include <string> using namespace std; int main() { string str ; cin >> str ; const string vowels = "aeiouAEIOU" ; int n_vowels = 0 ; for( string::size_type pos = str.find_first_of(vowels) ; pos != string::npos ; pos = str.find_first_of(vowels,pos+1) ) … | |
Re: if you are using c++ we can write portable code [code=cplusplus] std::cin >> std::noskipws ; char ch ; std::cin >> ch ; if( ch == '\t' ) /* ... */ ;// tab else /* ... */ ; // something else [/code] | |
Re: u could memory map the file (unix mmap/mmap64 or windows CreateFileMapping/MapViewOfFile) to reduce the i/o overhead (or use a large file buffer with C/C++ file i/o). | |
Re: see [url]http://www.codeproject.com/win32/quaker1.asp[/url] [url]http://msdn2.microsoft.com/en-us/library/ms633540.aspx[/url] [url]http://msdn2.microsoft.com/en-us/library/2ha2ha35(vs.80).aspx[/url] | |
Re: one way to do this is a. pad the matrix with null chars on all four sides. b. search for the word in each row using strstr.(EAST) c. rotate the matrix by 90 degrees and repeat (NORTH) d. rotate the matrix by 90 degrees and repeat (WEST) e. rotate the … | |
Re: Index = 1; should be inside the outer while loop. | |
Re: a. you should be able to get a more accurate output by using cout << fixed << setprecision(5). b. the accuracy of the mantissa of a floating point value on a c++ implementation can be gauged from std::numeric_limits<float>::digits. rough accuracy for reasonable small values would be within += std::numeric_limits<float>::epsilon() | |
Re: istream::getline (both the two arg and the three arg versions) fill a c-style array with characters read from an input stream. characters are extracted upto a maximum of n-1 (where n is the second arg) or the delimiter (defaults to a newline in the two arg version, the third arg … ![]() | |
Re: if there is only one variable length string in the class we could [code] #include <cstring> #include <cstdio> using namespace std; struct some_struct { static some_struct* construct const char* s ) { int n = strlen(sz) ; some_struct* pss = static_cast<some_struct*>( new char[sizeof(some_struct)+n] ) ; pss->string_sz = n ; strcpy( … | |
![]() | Re: the compare function should have this signature: int (*)(const void*, const void*) a. declare the function with the right signature. b. in the definition, cast the args to const suitorData*, then compare. |
Re: it is much easier if u use the c++ std library. [code] #include <iostream> #include <fstream> #include <iterator> #include <map> #include <algorithm> #include <cctype> using namespace std; struct print_it { inline void operator() ( const pair<char,int>& p ) const { cout << p.first << " occurs " << p.second << … | |
Re: [code] #include <iostream> #include <fstream> #include <map> #include <algorithm> using namespace std; struct print_it { void operator() ( const pair<char,int>& p ) const { cout << p.first << " occurs " << p.second << " times\n" ; } }; int main( int argc, char** argv ) { if( argc != … | |
Re: [code] #include <vector> #include <algorithm> struct some_struct { int key ; /* ... */ }; struct has_same_key { explicit ( const some_struct& s ) : what(s) {} bool operator() ( const some_struct& elem ) const { return elem.key == what.key ; } const some_struct& what ; }; inline std::vector<some_struct>::const_iterator do_find( … | |
Re: and first download the windows platform sdk if u already do not have it. [URL]http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en[/URL] |
The End.