maybe u could post more code. ur code is too cryptic for any form of debugging. esp post in detail how u called the code in the class and how the user select from a menu. normally, a scrolling screen is due to a improper looping. in this case, it might be because u've tried to use a while loop to get the user input from the menu, until the user decides to terminate the program with a special character, right? try removing the loop first if this is the case, and debug again. it's not difficult to code in c++ at all, just that you're not used to it. i've coded genetic algoritms, ant colony system and dijkstra's algorithm all in c++, with each algorithm averaging 1.5 weeks. i can't even begin to think of how to start my coding in VB.. "Learning does not make one learned: there are those who have knowledge and those who have understanding. The first requires memory, the second philosophy." - Abbe Faria, The Count on Monte Cristo
ng kok chuan
Posts
-
simple keyboard input ? -
simple keyboard input ?yup, i guess u're right. i've been too well-trained to think lean and mean :p.. however, using strings still have their advantages, as it dynamically allocates memory. this can help to prevent some wise user from entering longer than allocated mem space. "Learning does not make one learned: there are those who have knowledge and those who have understanding. The first requires memory, the second philosophy." - Abbe Faria, The Count on Monte Cristo
-
simple keyboard input ?ok, two things. firstly cin.get() only gets single characters, one at a time. cin.getline() will get a whole line, up to the end of the '\n' character. i'm not sure what u're doing here.. is this a class or the main method? if u're in the main method, this-> does not have any value associated to it at all. as i said, using a string solves a lot of problems. since u're using c++, u should use the available STLs (standard template libraries) whenever possible. using a char array in c++ is indeed foolhardy. using the code i wrote previously, u can pass the string as a reference. // class declaration class myclass { public: void mymethod(string&); }; // method declaration void myclass::mymethod(string &instr) { cout<
-
simple keyboard input ?is there any limitations on the type used? i guess this is for a school project right? if your project does not have any limitations, use the string class. #include using std::cout; using std::endl; using std::cin; #include using std::string; using std::getline; int main() { string test; cout << "name :"; getline(cin,test); cout << "Hello " << test << endl; return 1; } this effectively removes any limitiations on character size inputs, which imho, is bad. imagine you have an indian name (no offence intended) and an english name. normally indian names are longer, so if you used a larger array size, the english name wastes a lot of memory. string dynamically allocates the memory spaces, so nothing is wasted. and you don't have to explicitly deal with the memory size (i.e. no magic numbers). lastly, you'll find that getline will require you to press return twice to get the line if u're using vc++. this is a bug in the implementation of string. follow http://www.tek-tips.com/faqs.cfm?fid=5193 to fix the bug. hope this is clear enough. "Learning does not make one learned: there are those who have knowledge and those who have understanding. The first requires memory, the second philosophy." - Abbe Faria, The Count on Monte Cristo
-
changing a part of a stringi've checked the string class, and it also contains a replace member function, so essentially you can do the same thing that alok said for the CString class. anyway here's more definitions for the string class: http://www.cppreference.com/cppstring/[^]
-
Let me know my mistake in arrays program!!gack... that's a hell of a long code just to check for unique numbers.. if all u're interested in is getting is getting unique numbers, why not use STL to do your work for u? look at this link: http://www.cppreference.com/cppset/[^] using a set stl, it automatically keeps only the unique numbers during an insertation. and by using the pair insert( const TYPE& val ); esp, the bool, u can check if the insertation took place. for the lazy coder (that's me), my insert statement is: if (!(mySet.insert(myVal)).second) // so i don't have to use declare a pair :) cout<<"insertation has failed as it is duplicate."<
-
Reading blank linesi think that using ifstream and the "<<" operators (forgot what it's called...) will get u what u want. do something like this: while (!file.IsEOF()) // read all lines, even if it's blank. { __file >> B; } if (!B.empty()) // forgot if this works or not. think it should. __// do the required operation here. anyway think my code is pretty unclear. here's the explanation. just keep readin the file, and before performing the push_back operation for the vectors, check that the string is not empty. this will prevent empty string from being written into the vectors. and as the IsEOF() function stops the while loop only on eof, the blank lines will be read. hope this is correct, as i'm coding off-line here.
-
Closing consoles running appserm, wouldn't ctrl-break solve the problem? it'll terminate the program, if that's all that u're looking for.
-
need a source codei've recently programmed dijkstra in vc++. if u like i could send it to you. however i can only send u the dijkstra class as the rest of the classes are classified, so it won't compile. but u can get an idea of how dijkstra can be implemented. pm me if u like.
-
Package VC++ as static standaloneit's cos the other files can't be installed as dlls. i'm using dlls from oracle and visual studio c++, and in order to use those dlls, it requires oracle and vc++ to be installed. i've tried registering the files manually but it doesn't work. hence the requirement to package as a static file instead of using dlls. sigh, weird solution to a weird problem...
-
Package VC++ as static standalonei've already done the settings. the problem arises when i try to use another computer that doesn't have the libraries already installed. when i do so, the program won't work and it will complain that the libraries are not available. the problem is i can only have one file to push, as i'm doing a activex object. so i need to package those additional dlls/libs into the dll that i'm creating. please help, i'm tearing my hair out! :(
-
Visual Studio 6.0 bugit isn't safe for linux to allow that actually. imo what vc++ did is correct. anyway if u want a zero-sized array, do u mean u're going to allocate memory to the array on the fly? if so, u should declare it as a pointer. i.e. T *ptr; then u should use new and delete to alloc and free the memory respectively. even better, use vectors as it does all the memory handling for u. http://www.roguewave.com/support/docs/sourcepro/stdlibref/vector.html[^]
-
changing a part of a stringyou should tokenize the string with a delimiter of your choice, then append the tokens back into your string. // code for tokenizing, taken from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^] void Tokenize(const string& str, vector& tokens, const string& delimiters = " ") { // Skip delimiters at beginning. string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". string::size_type pos = str.find_first_of(delimiters, lastPos); while (string::npos != pos || string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } }
-
CString or stringwhat's the difference between CString and string? which one will be better and easier to use? so far i'm always sticking to string, as i learnt it that way. someone please enlighten me the advantages of CString over string.
-
Package VC++ as static standaloneyes, i do have the lib file. u mean *.lib right? i have that. so how can i statically link it?
-
Package VC++ as static standalonehi, thanks for replying. what do u mean by don't specify an external dll? i'm using oracle and so, i do have to use a certain oracl32.lib would that be what u mean?
-
Package VC++ as static standalonehi, i'm trying to package my console program as a static standalone, i.e. make it such that it does not require any dlls/libs on the client machine. can someone tell me how to do it?? thanks a lot!
-
need a function for c languageu might want to take a look at dijkstra's algorithm. google it and take the first link.
-
how to check if a reference is NULLRyan Binns wrote: What's wrong with what's there? Is concise, easy to understand, easy to maintain... Why make it harder? it's just for knowledge's sake... :) and thanks for clarifying the reference. so i'm not wrong when i changed everything to return pointers. now my code looks incomprehensible.. with both pointers and references... and i'm not going to go and standardize my code :p it's going to be fine as it stands.
-
how to check if a reference is NULLhi, i have a class that is defined below: class DVertex { public: DVertex(MazeNode*) { this->node = n; this->parent = NULL; this->cumulativeCost = DBL_MAX; } // member functions void update(MazeNode*, double); // update the parent and cost. double getCCost() const { return cumulativeCost; } // required to relax the node. MazeNode& getNode() const { return *node; } // required to identify the node. MazeNode& getParent() const { return *parent; } // required for reverse lookup. private: MazeNode *node; MazeNode *parent; double cumulativeCost; }; now the problem is when i tried to check the value of parent, i.e. void main() { DVertex v; if (v.getParent()==NULL) ; // do something } this will not work.. however if i change the class to return me MazeNode*, i.e. MazeNode* getParent() const { return parent; } then i can do that the check. anyone know how to check if a reference is null? and by the way, can tell me how to change the inline constructor to something shorter? i remember seeing something like Constructor( par1):var1=par1; but can't remember the exact syntax. thanks!!