Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
N

ng kok chuan

@ng kok chuan
About
Posts
24
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • simple keyboard input ?
    N ng kok chuan

    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

    C / C++ / MFC question c++ data-structures tutorial learning

  • simple keyboard input ?
    N ng kok chuan

    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

    C / C++ / MFC question c++ data-structures tutorial learning

  • simple keyboard input ?
    N ng kok chuan

    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<

    C / C++ / MFC question c++ data-structures tutorial learning

  • simple keyboard input ?
    N ng kok chuan

    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

    C / C++ / MFC question c++ data-structures tutorial learning

  • changing a part of a string
    N ng kok chuan

    i'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/[^]

    C / C++ / MFC help question

  • Let me know my mistake in arrays program!!
    N ng kok chuan

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

    C / C++ / MFC help

  • Reading blank lines
    N ng kok chuan

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

    C / C++ / MFC question c++ json help

  • Closing consoles running apps
    N ng kok chuan

    erm, wouldn't ctrl-break solve the problem? it'll terminate the program, if that's all that u're looking for.

    C / C++ / MFC help question learning

  • need a source code
    N ng kok chuan

    i'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.

    C / C++ / MFC c++

  • Package VC++ as static standalone
    N ng kok chuan

    it'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...

    C / C++ / MFC c++ tutorial question

  • Package VC++ as static standalone
    N ng kok chuan

    i'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! :(

    C / C++ / MFC c++ tutorial question

  • Visual Studio 6.0 bug
    N ng kok chuan

    it 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[^]

    C / C++ / MFC csharp visual-studio linux data-structures help

  • changing a part of a string
    N ng kok chuan

    you 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); } }

    C / C++ / MFC help question

  • CString or string
    N ng kok chuan

    what'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.

    C / C++ / MFC question

  • Package VC++ as static standalone
    N ng kok chuan

    yes, i do have the lib file. u mean *.lib right? i have that. so how can i statically link it?

    C / C++ / MFC c++ tutorial question

  • Package VC++ as static standalone
    N ng kok chuan

    hi, 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?

    C / C++ / MFC c++ tutorial question

  • Package VC++ as static standalone
    N ng kok chuan

    hi, 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!

    C / C++ / MFC c++ tutorial question

  • need a function for c language
    N ng kok chuan

    u might want to take a look at dijkstra's algorithm. google it and take the first link.

    C / C++ / MFC learning

  • how to check if a reference is NULL
    N ng kok chuan

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

    C / C++ / MFC help tutorial question announcement

  • how to check if a reference is NULL
    N ng kok chuan

    hi, 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!!

    C / C++ / MFC help tutorial question announcement
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups