1,296 Posted Topics

Member Avatar for ganbree

I can't understand what the OP snippet illustrates. By the way, reserve member argument defines new [b]total capacity[/b] but not capacity increment. Evidently, all pointers and references to vector elements are valid while [icode]v.size() <= v.capacity()[/icode]. That's because std::vector must have continuous storage for all its elements (by standard requienment). …

Member Avatar for ArkM
0
96
Member Avatar for phoenix911

Line by line, word by word: [code=cplusplus] void WordByWord(const char* filename) { if (!filename) return; ifstream file(filename); string line, word; for (int lineno = 1; getline(file,line); lineno++) { cout << "Line #" << lineno << ":\n"; istringstream words(line); while (words >> word) cout << word << '\n'; } } [/code] …

Member Avatar for Ancient Dragon
0
122
Member Avatar for GrilledTuna

1. Why semicolon after else? [code] else; // empty alternative?! cout << ... [/code] 2. [icode]string toString();[/icode] - the function returns string value, not a reference to anything. Now [code] List[K].toString() = "DELETED"; [/code] is absolutely senseless assignment to a temporary string value returned from toString() - in other words, …

Member Avatar for GrilledTuna
0
94
Member Avatar for Leopold

Alas, you need some (serious) redesign, for example: [code=cplusplus] double radius ( double& r, double& d, double& c ); double diameter ( double& r, double& d, double& c); double circumference ( double& r, double& d, double& c); const double Pi = 3.14159265358; int main() { double r, d, c; int …

Member Avatar for Mouche
0
151
Member Avatar for atman

You forgot to allocate +1 byte for zero char terminating C-string: [code=cplusplus] p = new char[strlen(s)+1]; [/code] Now you have memory leak: you forgot to deallocate this memory: [code=cplusplus] delete [] p; [/code] Well, it's evidently useless function... The 2nd snippet: [code] char* s; ... cin >> s; [/code] Pointer …

Member Avatar for vmanes
0
106
Member Avatar for nanchuangyeyu

Look at Project Properties|Linker|System and set the proper Stack Reserve Size parameter (in bytes - for example, set 3000000, see seedhant3s calculations). May be your IDE (VS 2005) has slightly different names for these parameters (I have VS 2008 now). Better try to avoid large local (automatic) array allocations, especially …

Member Avatar for ArkM
0
212
Member Avatar for newbie_newbie

It works: [code=cplusplus] template <typename T> class Sample { private: typedef std::vector<T> vectorType; vectorType vector; public: typedef typename vectorType::iterator vectorIterator; vectorIterator begin(); }; template <typename T> typename Sample<T>::vectorIterator Sample<T>::begin() { return vector.begin(); } [/code] An example from the C++ standard: [quote][code] template<class T> struct A { typedef int B; A::B …

Member Avatar for newbie_newbie
0
148
Member Avatar for kvprajapati

If you mean [i]variable argument list[/i], read this: [url]http://www.codeproject.com/KB/cpp/argfunctions.aspx?fid=15556&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=1066108[/url]

Member Avatar for kvprajapati
0
171
Member Avatar for lagirabo

>where am i going wrong??? here, there and everywhere ;) 1. What for floatSize? You never used it. 2. sizeof(bits) is a size of a pointer to unsigned char. It's not bear a relation to the problem. Fortunately it's equal to 4 on 32-bit CPU... 3. 128 as a bit …

Member Avatar for lagirabo
0
101
Member Avatar for johnnydarten

Declare class table member functions with [b]const[/b] parameters: [code=cplusplus] bool insert(const TKT& inskey, const TDT& insdata); ... [/code] Consider [icode]anytable.insert(6,"john")[/icode]. It's impossible to bind non-const std::string reference to char array "john". However it's possible to bind const std::string reference to temporary std::string object produced by "john" => std::string("john") conversion. Yet …

Member Avatar for johnnydarten
0
111
Member Avatar for elitedragoon

See [url]http://www.codeproject.com/KB/cpp/number_to_text_converter.aspx[/url] It's a program in C (I don't know why it's contained in .cpp file). Change sacramental [icode]void main[/icode] to standard [icode]int main[/icode]. It works (at least for 15000, 1500, 150 and 15 ;))...

Member Avatar for ArkM
0
146
Member Avatar for arenq

[QUOTE=arenq;872814]Can you tell me which basic operations on a list can cause an use of stack proportional to the size of the list? (I mean, looping on all elements...) I have problems with stack size. Is iterator post-incrementing dangerous in this sense?[/QUOTE] No need in recursive implementation of basic list …

Member Avatar for arenq
0
82
Member Avatar for Gurdinho

[code=cplusplus] #include <algorithm> ... std::random_shuffle(a,a+10); [/code] or with PRNG seed: [code=cplusplus] #include <algorithm> #include <ctime> ... srand(time(0)); ... std::random_shuffle(a,a+10); [/code]

Member Avatar for ArkM
0
100
Member Avatar for sanushks

No such library function: it's not well-defined specification. For example, how about this delimiters set: [code] { "!", "#", "#!" } [/code] ? Elaborate non-contradictory specifications. It's not so hard to write a proper tokenizer in C...

Member Avatar for cool_zephyr
0
212
Member Avatar for Sune

In modern C++ [i]condition[/i] is not the same thing as an expression. A condition can be a declaration, that's an example from the Standard: [code=cplusplus] int i = 1; while (A a = i) { //... i = 0; } [/code]

Member Avatar for e.shankar87
0
227
Member Avatar for cigur

[quote]An aggregate is an array or a class (clause 9) with no user-declared constructors (12.1), no private or protected non-static data members (clause 11), no base classes (clause 10), and no virtual functions (10.3).[/quote] It's possible to initialize class CA object (see OP) with [i]initializer-clause[/i] { ... } in the …

Member Avatar for tux4life
0
118
Member Avatar for radskate360

10..20 or 11..19 or what else? [icode][0,n)[/icode] - 0, 1, ... n-1 : [code] rand() % n [/code]

Member Avatar for ArkM
0
158
Member Avatar for preetchhabra

[QUOTE=preetchhabra;871368]i am new in programming in visual c++ can anyone tell that how can i call one form from other form means by clicking on button first form should disappear and second fom should come on screen in visual c++ 6[/QUOTE] No [i]forms[/i] in 11-years old Visual C++ 6...

Member Avatar for ArkM
0
73
Member Avatar for tizzo233

Of course, you got memory access exception: initial head == 0 but you are trying to assign new node pointer via this null pointer: [code=cplusplus] head->name = new char ... [/code] Regrettably you did not set the language specifier into the code tag so no line numbers in your snippet. …

Member Avatar for tizzo233
0
154
Member Avatar for m.s.sigdel

There are lots of PDF libraries for C and C++. For example, look at [url]http://www.freebyte.com/programming/cpp/#freecpppdflibraries[/url] (it's not a complete list). I'm sure that you need 32-bit C++ compiler (as soon as possible, not only for pdf libraries)...

Member Avatar for tux4life
0
100
Member Avatar for Dewey1040

>any suggestion on where to start? Start from [url]http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_sorting.aspx#merge[/url]

Member Avatar for ArkM
0
178
Member Avatar for utkarsh sharma

Try winbgim or winBGI libraries - BGI for Windows (search Google). Regrettably (or fortunately), I have never used these libraries...

Member Avatar for WaltP
1
172
Member Avatar for waldchr

Place this function into the separate .cpp file: [code=cpluplus] void ShowText(const char* filename) { ::ShellExecuteA(::GetDesktopWindow(), "open", "notepad.exe", filename, 0, SW_SHOWNORMAL); } [/code] Include <windows.h> dependency into this file only. This function works in console applications too.

Member Avatar for waldchr
0
213
Member Avatar for Qousio

>what is a good way to initialize a variable in a function, just once? [code=cplusplus] ... f(...) { static bool var = true; ... } [/code] As usually, it's a symptom of a bad design ;)...

Member Avatar for ArkM
0
149
Member Avatar for youngfii

I don't understand why you don't understand... ;) Line #15: unitialized variable guess is compared with random. Unitialized means that the value of this variabe is undefined: it's a garbage. You will get the value in the next statement! Back to the Future game... No comments...

Member Avatar for ArkM
-1
71
Member Avatar for 35nando
Member Avatar for neigyl_noval
0
322
Member Avatar for bunnyboy

That's it: [code=cplusplus] if ( top_ == size ) resize(); [/code] See what happens: 0. empty stack of size 1 (for simplicity); top_ = -1 1. push; top_ != size, OK, top_ = 0 now, stack full! 2. push again: WARNING: top_ != size, NO resize!!! ... ... and you …

Member Avatar for bunnyboy
0
112
Member Avatar for saw iv

[QUOTE=saw iv;869952]i want from any one to write the following programme for me i want it by graphics & off course i want the full programme i want the programme written in borland c++ [U] The programme:[/U] it is required to build an application which simulates the famous connect-4 game. …

Member Avatar for WaltP
-2
77
Member Avatar for newcook88

[QUOTE=newcook88;869935]how do i create a set method to get the fstream input file. in need to be able to define the file location in the main method. [CODE]class a { private: ifstream fileOne; ofstream report1; public: void setinput(std::ifstream& in); void setoutput(std::ofstream& out); }; [/CODE] how can i code these set …

Member Avatar for ArkM
0
182
Member Avatar for jtltgl

>i hope i did tag right on code posted. Alas, correct tags are: [noparse][code=cplusplus] source [/code][/noparse]

Member Avatar for jtltgl
0
132
Member Avatar for power_computer
Member Avatar for Ace01000

[QUOTE=khalf;869894]i have the same problem[/QUOTE] You have the same solution. Are you sure that it's a good idea to reanimate 3-years old thread?

Member Avatar for ArkM
0
179
Member Avatar for nanchuangyeyu

What is it: [i]abstract values[/i]? May be you mean [b]absolute[/b] value? reinterpret_cast considered harmful ;) [code=cplusplus] typedef std::basic_ifstream<short> ishortints; typedef std::basic_ofstream<short> oshortints; void doIt(const char* source, const char* target) { if (!source || !target) return; ishortints fraw(source,ios_base::binary); oshortints fabs(target,ios_base::binary|ios_base::app); short x; if (fraw && fabs) while (fraw.get(x)) { x = …

Member Avatar for ArkM
0
133
Member Avatar for rizillion

1. Next time use code tag with the language specifier: [noparse][code=cplusplus] source [/code][/noparse] 2. Double apostrophes (empty character constant) is not a valid construct in C++ (have you ever seen the compiler diagnostic messages? ): [code=cplusplus] cout<<str2+''+str3+''+str1<<endl; [/code] Use ' ' for the space character.

Member Avatar for neigyl_noval
0
98
Member Avatar for kvprajapati
Member Avatar for khenz

Probably you place class implementations in .h files (at least for gameSequence and difficultySelection classes). That's why you have gameSequence.obj object module (see diagnostics in OP), for example (correct .h files w/o implementation codes are never produced object modules). Of course, after that you have these classes implementation in every …

Member Avatar for ArkM
0
137
Member Avatar for QuintellaRosa

If the program runs on a little-endian computer: [code=cplusplus] inline std::string int2String(dWord n) // unsafe programming { char* p = reinterpret_cast<char*>(&n); return std::string(p,sizeof n); } [/code] Platform-independent (more precisely, LSB/MSB-independent) code is a few cumbersome... Apropos, your [icode]*reinterpret_cast<dWord*>(...)[/icode] expression is not portable at all: how about proper (for dWord* pointer) …

Member Avatar for ArkM
0
255
Member Avatar for lolguy

>i began reading K&R ... Well, let's read the next sentence after squeeze function definition: [quote]Each time a non-c occurs, it is copied into the current j position, and only then is j incremented to be ready for the next character. This is exactly equivalent to [code=c] if (s[i] != …

Member Avatar for lolguy
0
163
Member Avatar for Liszt

See also ToLowerInvariant() function: [url]http://msdn.microsoft.com/en-us/library/system.string.tolowerinvariant.aspx[/url]. MS recommends ToLowerInvariant for OS identifiers (file names, registry keys etc)...

Member Avatar for Liszt
0
209
Member Avatar for daviddoria

[QUOTE=daviddoria;869304]I want to make an input stream parser capable of handling input in any of the following forms: [code] x y z x,y,z x, y, z (x,y,z) (x, y, z) [/code] Is there a clever way to do this? Or do I have to check the first character, if it …

Member Avatar for ArkM
0
86
Member Avatar for dav555

[QUOTE=dav555;869241]how can i convert a hex value of a byte (unsigned char) to a short value? [code="c++"] unsigned char hexByte = 0x02; short value= ??? [/code] thank you for your help![/QUOTE] As usually: [code=cplusplus] short value = hexByte; [/code] What's a problem?

Member Avatar for dav555
0
285
Member Avatar for massivefermion

You can't run this program; moreover, you can't compile it: [code=c++] int *result=pfact(n); // You declare a pointer to int for (int i; result[i][0] !=0; ++i) { // You are trying to subscript result if(result[i+1][0]!=0) ... // result[i] is int and now you are trying // to index this int …

Member Avatar for iamthwee
0
147
Member Avatar for goyofoyo

And what for friend arith operators? [code=cplusplus] fraction operator+(const fraction& f) const; ... [/code]

Member Avatar for goyofoyo
0
116
Member Avatar for newcpp

No problems with v1 and v2: these members constructors create empty vectors. You can initialize them in Grid constructor(s) or later in the special member function (let it's named as init or what else), for example: [code=cplusplus] explicit Grid::Grid(size_t n): v2(n), v3(n) {} // or void Grid::initv2(const std::vector<int>& v) { …

Member Avatar for newcpp
0
7K
Member Avatar for CppBuilder2006

The answer: use anonymous namespace... [code=cplusplus] using std::cout; class A // External linkage name { public: void f() { cout << "::A:f()\n"; } }; namespace { // Internal linkage area: class A // Internal linkage name { public: void f() { cout << "LocalA::f()\n"; } }; typedef A LocalA; // …

Member Avatar for CppBuilder2006
0
332
Member Avatar for gretty

Yet another approach (undestructive test): [code=cplusplus] bool is1in2(const int* a1, const int* a2, int n) { int j; for (int i = 0; i < n; i++) { for (j = 0; j < n && a[i] != b[j]; j++) ; if (j == n) return false; } return true; …

Member Avatar for siddhant3s
0
4K
Member Avatar for shea279

>I looked on google ... After ~15 seconds: [url]http://www.codeproject.com/KB/recipes/csha1.aspx[/url] [url]http://www.packetizer.com/security/sha1/[/url] What's a problem?

Member Avatar for ArkM
0
152
Member Avatar for iconz113

Simply tell the story: [code] open input file if the file is not opened print message stop endif // read_the_next_record means: // read hours, payrate, Overtime, Regpay while read_the_next_record is OK ... see OP pseudocode endloop close input file [/code] Pseudocode is not a formal language. Your teacher's pseudocode != …

Member Avatar for ArkM
0
243
Member Avatar for xiaojesus

>Class declaration means... Between you and me: this constuct called a class [b]definition[/b] in the C++ Standard... ;)

Member Avatar for Sky Diploma
0
89
Member Avatar for 3beer

[QUOTE=tux4life;853321][ICODE]ofstream infile;[/ICODE] // create a new output stream [ICODE]infile.open ("[I]yourfile[/I]", fstream::app);[/ICODE] // open the file for appending[/QUOTE] Output stream named [b]in[/b]file... That's cool! ;)

Member Avatar for 3beer
0
104

The End.