1,247 Posted Topics
Re: the problem with the code using unsigned it is that nowhere in the c++ standard does it say [ICODE]std::numeric_limits<unsigned int>::max() >= 2^32 - 1[/ICODE] or for that matter, [ICODE]std::numeric_limits<unsigned int>::radix == 2[/ICODE] or [ICODE]std::numeric_limits<unsigned int>::digits >= 32[/ICODE]. so the code may fail for some input values on some implementations. the … | |
Re: [code]int main() { int numbers[4]; int i; ifstream streamin; streamin.open("input.txt"); for(i=0;i<4;i++) { streamin >> numbers[i] ; } // [COLOR="Red"]what is the value of i at this point?[/COLOR] cout << numbers[i]; streamin.close(); }[/code] | |
Re: this is one way to do it. [code=c++]#include <iostream> #include <sstream> #include <iomanip> int main() { std::ostringstream stm ; stm << '$' << std::fixed << std::setprecision(2) << 123.4567 ; std::cout << std::setw(11) << std::setfill(' ') << std::right << stm.str() << '\n' ; }[/code] | |
Re: > my first time using shared memory and I'm really discouraged. it is just that the problem is (much) harder than you imagine it to be. for this to work, a shared memory segment should be created once and when allocate is called we have to sub-allocate memory blocks out … | |
Re: you could use librsync [url]http://librsync.sourceforge.net/[/url] to install (*BSD): as root, [ICODE]cd /usr/ports/net/librsync && make install clean[/ICODE] or for binary package: as root, [ICODE]pkg_add -r librsync[/ICODE] | |
Re: [CODE]// .. { this->progressBar1->Value = (out / count) * 100; this->progressBar1->Invalidate() ; this->progressBar1->Update() ; // if immediate repaint is required } // ..[/CODE] | |
Re: > In reality FuncA is a normal function in an exe, and FuncB is a function on a COM interface > (so FuncA actually calls CoCreateInstance before calling FuncB on the COM object). > And inside FuncB, DoSomethingElse is actually an ADO function that i am calling > on one … | |
Re: the problem is that you are calling a virtual function during the construction of the base class. this will not behave the way you expect it to behave; the wrong vtable is being pointed to at the time. if you call virtual functions during construction or destruction, such calls will … | |
![]() | Re: [CODE]std::string runasc "runas /profile /user:tsc\\staffuser" ; system( ( runasc + " " + programc ).c_str() ) ;[/CODE] |
Re: see: [url]http://www.devx.com/cplus/10MinuteSolution/30302/0/page/1[/url] | |
Re: for XP Professional: from the command prompt execute [B]gpedit.msc[/B] go to: Computer configuration --> windows settings --> scripts (startup/shutdown) choose Shutdown and add your script/command. | |
Re: [CODE]#include <iostream> using namespace std; int main(int, char**) { long long n = 6647817899LLU; long long f = 10299685494LLU; int i = ((f - n) / [COLOR="Red"]double(n)[/COLOR] ) * 100; cout << "Part 4: " << f << " is " << i << "% more than " << n … | |
Re: > I heard something that boost's preprocessor library can do that. > didn't get to try it out : [url]http://boost.org/libs/preprocessor/doc/ref/repeat.html[/url]. BOOST_PP_REPEAT gives a fast horizontal repetition from 0 to N-1 since you need a repetition starting at 1, using BOOST_PP_REPEAT_FROM_TO would be easier. [code=c++]#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/repetition/repeat_from_to.hpp> #include <iostream> #define … | |
Re: the major disadvantage of dynamic analysis is that its results may not generalize to future executions. there is no guarantee that the test suite over which the program was run (that is, the set of inputs for which execution of the program was observed) is characteristic of all possible program … | |
Re: > ... so, what should i change in the coding to solve the problem? change the return type from void to bool [CODE]template < class DataType> class List { // ... [COLOR="Red"]bool[/COLOR] Traverse(DataType, int &); // ... };[/CODE] | |
Re: [QUOTE=Jennifer84;536793]I have 2 Forms in my Windows Form application. Form1 creates .txtfiles. I open Form2 from Form1 and can see the .textfiles that is created in a comboBox3. If I open the application from the beginning and go to Form2 I will see all .txt files that exists in a … | |
Re: > It has to be like this; "CurrentDirectory" + "\\test.jar" or something. so just use a relative path "test.jar". and put the .exe and the .jar in the same folder. [CODE]ProcessStartInfo^ minProssesStartInfo = gcnew ProcessStartInfo( "test.jar" ) ; [/CODE] | |
Re: the simplest way would be to use a streambuf that outputs to the control the skeleton would be: [code=c++] #include <streambuf> class textbox_streambuf : public std::streambuf { // ... protected: virtual int overflow( int c = traits_type::eof() ) { if ( c != traits_type::eof() ) { char cc = traits_type::to_char_type(c); … | |
Re: [code=c++]#include <string> #include <algorithm> #include <iostream> using namespace std ; int main() { string MyString = "The rabbit likes to ea! carro!s"; cout << MyString << '\n' ; replace_copy( MyString.begin(), MyString.end(), MyString.begin(), '!', 't' ) ; cout << MyString << '\n' ; }[/code] | |
Re: The definition `void main() { /* ... */ }` is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts `int main() { /* ... */ }` and `int main(int argc, char* … | |
Re: > The data is basically alot of text and integer values. > It needs to be accessed, sorted and filtered > Not much data will be added maximum size will go to 400K just use a simple xml file to store the data. and an xml parser library eg. [url]http://www.grinninglizard.com/tinyxml/[/url] | |
![]() | Re: > since I only defined function() once. you defined it twice. once in a.cpp and once in main.cpp (which includes a.cpp) |
Re: > Anyone been there, done that? no, i haven't done anything of the kind. but i do know that the *bsd unixes do provide (sometimes limited) binary emulation for a variety of operating systems. i think NetBSD would be the best option for attempting this. the part of the kernel … | |
Re: the exception thrown is of type [B]float[/B], not [B]int[/B] you have to catch it as a float. [icode]catch( float nValue ) { /* ... */ }[/icode] | |
Re: > I have: Directory::GetFiles(Files,"*.txt"); > Files is in a format: cli::array<Type,dimension> ^ > How could Files be converted to System::string ^ presumably, the Type in [ICODE]cli::array<Type,dimension>[/ICODE] is wchar_t and the dimension is 1. all cli array types derive from [ICODE]System::Array[/ICODE] and you could directly use the constructor of a [ICODE]System::String[/ICODE] … | |
Re: > I have seen some code where some variable gets inserted into string through the % sign the code you saw was probably using the [B]Boost.Format[/B] library to insert stuff into a stringstream. [url]http://www.boost.org/libs/format/doc/format.html[/url] | |
Re: > how do i make the final calculation become 41.6 ? [code=c++]#include <iostream> #include <iomanip> #include <sstream> int main() { std::cout << 374.0 / 9.0 << '\n' ; std::cout << std::fixed << std::setprecision(1) << 374.0 / 9.0 << '\n' ; std::stringstream stm ; stm << std::fixed << std::setprecision(1) << 374.0 … | |
Re: write a function to covert a text file to an xml file. have two nested loops; the outer one to iterate over the folders, and the inner one to iterate over files in that folder. [code=c++]#include <fstream> #include <string> #include <iomanip> #include <sstream> void convert_to_xml( std::istream& in_file, std::ostream& out_file ) … | |
Re: [url]http://msdn2.microsoft.com/en-us/library/1b4az623.aspx[/url] [url]http://msdn2.microsoft.com/en-us/library/1b4az623(VS.80).aspx[/url] [url]http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx[/url] | |
Re: > I'm wondering if there is a more elegant solution. perhaps use a parser framework like boost.spirit [url]http://www.boost.org/libs/spirit/index.html[/url] | |
Re: a commonly used architecture is [url]http://en.wikipedia.org/wiki/Model-view-controller[/url] > Right now, I'm thinking along the lines of having two main objects, a Screen and a Handler these roughly correspond to view and controller lines, circles etc. would be part of the model. | |
Re: or use a union [code=c++]int main() { typedef unsigned char byte ; union { byte buffer[ sizeof(long) ] ; long key ; }; // ... }[/code] | |
Re: > the following piece of simple code(it didn't work in any of the compilers VC++,GCC etc) the code is incorrect and should not compile without an error. this is (a simplified version) of what the standard says about while loops: [quote]in [B]while(condition) substatement[/B] the condition is one of i. expression … | |
Re: [CODE]template<typename DataType> class Value { // ... Value& operator +(const Value& aValue); // .. }; template<typename DataType> Value<DataType>& Value<DataType>::operator +(const Value<DataType>& aValue) { /* ... */ } [/CODE] this [B]operator+()[/B] only allows two Value template instantiations for the same DataType to be used. ie. you could add a [B]Value<int>[/B] to … | |
Re: > For some reason reference to operator() bothers me. Am I missing something simple? one reason why this may be a bother is possible loss of efficiency. a function called via a pointer is usually not inlinable. (what a pointer points to is techically something that is known only at … | |
Re: your compiler may require [ICODE] c = std::pow( a, b ) ;[/ICODE]. this is correct as you are using <cmath> (not math.h) the more likely reason is that the function pow is overloaded in c++ [code]double pow ( double base, double exponent ); long double pow ( long double base, … | |
Re: this is an issue in the c++98 standard. this has been addressed by The Library Working Group (LWG), the ISO subcommittee responsible for making changes to the std c++ library. a proposed resolution to this [url]http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#136[/url] has been adopted in the Tokyo meeting of the LWG (2000?) and should make … | |
Re: > stores each unique word and the frequency it appears in the text file. > This information is stored in a multimap<string, int> it would be simpler to use a [B]std::map<std::string, int>[/B] (instead of a std::multimap) [code=c++]std::map<std::string, int> word_count ; std::string word ; while( read_next_word( file, word ) ) ++word_count[word] … | |
Re: yes, it is valid (and as efficient and more flexible) to use &Base::Go instead of &Derived::Go. pointers to member functions do not support an operator(); so they are used as if [B]boost::mem_fn[/B] has been used to convert the member pointer into a function object. [B]boost::bind(&Base::Go, _1)[/B] is equivalent to [B]boost::bind( … | |
Re: you would have to iterate through the vector and remove each element that is reset. moving all the reset elements to the back of the sequence and then doing a single erase of elements at the end of the vector (as in your code) seems to be the most efficient … | |
Re: > is there a way how to ... kill process at once? posix: [B]kill( process_id, SIGKILL ) ;[/B] [url]http://www.hmug.org/man/2/kill.php[/url] [url]http://www.hmug.org/man/3/signal.php[/url] windows: [B]TerminateProcess( process_handle, exit_code ) ;[/B] [url]http://msdn2.microsoft.com/en-us/library/ms686714(VS.85).aspx[/url] | |
Re: RTTI introduces both space and time overheads. there is a per class space overhead to store the type information; most implementations use about 40 bytes or so per class. finding the type_info (typeid on a reference to polymorphic type) involves getting to the vtable and locating the most derived class … | |
Re: > Can any 1 brief me abot, what static code analysis is. [url]http://en.wikipedia.org/wiki/Static_code_analysis[/url] > And few links, where i can get freeware or open source codes for such analysing tools [url]http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis[/url] | |
Re: > error C2297: '%' : illegal, right operand has type 'double' the error message says it all, doesn't it? > should I convert result of power to type int? yes. either [ICODE]binary % ( i * int( pow(10,i) + 0.5 ) ) ;[/iCODE] or [ICODE]binary % ( i * int( … | |
Re: > how will you make your structure be in within structure ??? at the namespace level [code=c++]struct outer { // ... struct inner { // ... }; // .... };[/code] at the object level [code=c++]struct composite { // ... outer member_one ; outer::inner member_two ; // ... };[/code] | |
Re: [CODE]char* soundex( const char word[], char sound[] ) { // ... sound="Z0000"; // *** trouble **** // ... }[/CODE] a literal string (eg "Z0000") consists of non-modifiable chars. if you had enabled all warnings, the compiler would have alerted you that something was amiss here. eg. [B]warning: deprecated conversion from … | |
Re: > Hmmm, is there any significant, practical difference? > I think not. Remember, that was 40 billion iterations. for standard types like int or double, it would not make any difference. the compiler knows everything about these types and can see that [icode]a = a + b ;[/icode] and [icode]a … | |
Re: > which compiler is the most popular the two mainstream c++ compilers are g++ (part of gcc) and vc++ (microsoft). and it is probably a good idea to stick to one of these; they are the most popular and attract the best support from third-party library and tool developers. both … | |
Re: for storing and accessing a sequence of objects in memory, you cannot have a construct more efficient (in terms of both time and space) than an array. it is, however, also a very low level data structure with two fundamental properties: a. an array doesn't know its own size. b. … | |
Re: [url]http://www.boost.org/doc/html/any.html[/url] [url]http://www.boost.org/doc/html/variant.html[/url] you may also find this discussion on static typing technology at large interesting. [url]http://groups.google.com/group/comp.std.c++/browse_thread/thread/da71464ad690d506/303e3bf2407a7609?lnk=st&q=min+max+c%2B%2B+#303e3bf2407a7609[/url] |
The End.