Results 1 to 7 of 7

Thread: Alternative to cin??

  1. #1
    Join Date
    Oct 2004
    Posts
    393
    Rep Power
    0

    Default Alternative to cin??

    First off, good day to all. I was wondering if anyone know of an alternative to cin [c++]. cin has a limitation that i cant seem to bypass efficiently.

    If keystroke "enter" is pressed it takes you to a new line [like that of scanf] rather than terminate entry like gets().

    Oh, in case you ask, "why not just use gets_s()", gets_s cant handle datatype "string" only "char*".
    Moving forward never back. That's my way of life.

  2. #2
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    My C++ is weak so I can't really address your question, but if gets_s() does what you want, then you can just assign the char* to a C++ string. This, for instance, works:

    Code:
    #include <iostream>
    using namespace std;
    
    int main() {
    	char cstring [50];
    	gets(cstring);
    	string cppstring = cstring; //this
    	cout << cppstring << endl;
    	
    	return 0;
    }
    Yeah yeah unsafe code.

  3. #3
    Join Date
    Oct 2004
    Posts
    393
    Rep Power
    0

    Default

    Thanks for the code but not what am looking for. Datatype string is more flexible to use than char*. Reason? It can be overloaded. char* is constant so it cannot. gets() only handles char* not string but i hate the fact that cin doesnt terminate a null entry. A value has to be entered before terminating and thats where my problem lies.
    Moving forward never back. That's my way of life.

  4. #4
    Join Date
    Dec 2008
    Posts
    207
    Rep Power
    0

    Default

    C++ is old! you need to stop use that cr@p!
    Orlando aka Maskelly
    __________
    If you buying, im selling!

  5. #5
    Join Date
    Oct 2004
    Posts
    393
    Rep Power
    0

    Default

    There's so many "old languages" out there, oddly enough, we all have to start somewhere. School is the "perfect place" we start and you are no different. So unfortunately, I and to a greater extent "us", cannot go beyond what they're currently administering as treatment in learning. We can teach ourselves new languages but the fact is, it wont value anything unless converted or done in the present "old language" that is being taught.
    Moving forward never back. That's my way of life.

  6. #6
    Join Date
    Dec 2008
    Posts
    207
    Rep Power
    0

    Default

    true! keep studying my friend.... an when you find an alternative to cin let me know cuz i have never heard of it.... lol

  7. #7
    Join Date
    Dec 2002
    Posts
    500
    Rep Power
    0

    Default

    cin.get or cin.getline something like that.

    there are methods on the stream classes, not just the stream insertion and extraction (>> , <<) operators.
    Cultured in Aggression and Koding like a Warrior!!
    “Common sense is instinct. Enough of it is genius.” - George Bernard Shaw.
    "The significant problems we face cannot be solved by the same level of thinking that created them." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •