1,247 Posted Topics

Member Avatar for thekashyap

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 …

Member Avatar for vijayan121
0
305
Member Avatar for Reema_Hamed

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]

Member Avatar for Reema_Hamed
0
188
Member Avatar for FoX_

> 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 …

Member Avatar for FoX_
0
130
Member Avatar for katzumi_r

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] …

Member Avatar for vijayan121
0
155
Member Avatar for winbatch

[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. …

Member Avatar for vijayan121
0
361
Member Avatar for civil1

[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 …

Member Avatar for Ancient Dragon
0
248
Member Avatar for avi_new

[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] …

Member Avatar for Ancient Dragon
0
194
Member Avatar for raj157

[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 ; }; …

Member Avatar for vijayan121
0
314
Member Avatar for pjakubo86

make your operator< const correct. [code][COLOR=#000000] bool Node::[/COLOR][COLOR=#000000]operator< ( const Node&) const [/COLOR][/code]

Member Avatar for vijayan121
0
407
Member Avatar for squinx22

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]

Member Avatar for vijayan121
0
99
Member Avatar for B.Y

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 …

Member Avatar for WaltP
0
10K
Member Avatar for FreeFull

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).

Member Avatar for vijayan121
0
158
Member Avatar for jasssvj

[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 …

Member Avatar for vijayan121
0
1K
Member Avatar for Tauren

[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 …

Member Avatar for WaltP
0
130
Member Avatar for Brent.tc
Member Avatar for vijayan121
0
245
Member Avatar for nanodano

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]

Member Avatar for vijayan121
0
188
Member Avatar for student86

[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* …

Member Avatar for vijayan121
0
91
Member Avatar for ithelp

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. …

Member Avatar for vijayan121
0
114
Member Avatar for earlyriser

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 …

Member Avatar for earlyriser
0
80
Member Avatar for emr

[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 …

Member Avatar for Aia
0
194
Member Avatar for tasomaniac

[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 …

Member Avatar for TkTkorrovi
0
701
Member Avatar for Aia

[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 …

Member Avatar for vijayan121
0
487
Member Avatar for jan1024188

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.

Member Avatar for vijayan121
0
300
Member Avatar for LieAfterLie

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] …

Member Avatar for vijayan121
0
122
Member Avatar for muadh jamal

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 …

Member Avatar for WaltP
0
3K
Member Avatar for RisTar

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.)

Member Avatar for WaltP
0
114
Member Avatar for Daniel E

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 …

Member Avatar for vijayan121
0
119
Member Avatar for Lance Wassing

[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 …

Member Avatar for Infarction
0
203
Member Avatar for SHWOO

you forgot to terminate the definition of the class with a [B]; [code] [/B]class __gc whatever { } // need a semicolon here [/code]

Member Avatar for vijayan121
0
147
Member Avatar for adnichols

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 …

Member Avatar for adnichols
0
134
Member Avatar for satish.paluvai

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 = …

Member Avatar for vijayan121
0
82
Member Avatar for Tales

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 …

Member Avatar for vijayan121
0
143
Member Avatar for desijays

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

Member Avatar for desijays
-1
159
Member Avatar for ntredame

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) ) …

Member Avatar for ntredame
0
4K
Member Avatar for ajaxjinx

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]

Member Avatar for vijayan121
0
988
Member Avatar for Lance Wassing

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).

Member Avatar for WaltP
0
134
Member Avatar for jan1024188

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]

Member Avatar for jan1024188
0
142
Member Avatar for jerryseinfeld

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 …

Member Avatar for Lerner
0
192
Member Avatar for afr02hrs
Member Avatar for thekashyap

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()

Member Avatar for thekashyap
0
1K
Member Avatar for Derice

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 …

Member Avatar for iamthwee
0
135
Member Avatar for n.aggel

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( …

Member Avatar for n.aggel
0
115
Member Avatar for sakura_fujin

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.

Member Avatar for vijayan121
0
173
Member Avatar for ericelysia

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 << …

Member Avatar for vijayan121
0
136
Member Avatar for Jasy
Re: C++

[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 != …

Member Avatar for Lerner
0
121
Member Avatar for MIGSoft

[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( …

Member Avatar for vijayan121
0
182
Member Avatar for bento

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]

Member Avatar for Ene Uran
0
368

The End.