question

This is a discussion on question within the C++ Programming forums, part of the General Programming Boards category; i know gow to get characters from a file using in_stream.get(next). is there a way to get characters from a ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    57

    question

    i know gow to get characters from a file using in_stream.get(next). is there a way to get characters from a user instead of from a file and how would i do this.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    #include <iostream>

    main(void)
    {
    int x;
    int y;
    cout<<"please enter something x"<<endl;
    cin>>x;
    cout<<x<<":::blab"<<endl;
    cin.get();
    cout<<"please enter something y"<<endl;
    y = cin.get();
    cout<<y<<":::blab"<<endl;
    }

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    i dont understand how that would work......wouldnt it get an integer instead of a character. i want to be able to have the user enter a sentence and access that sentence one character at a time.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    #include <iostream>

    main(void)
    {

    char xp;

    cout<<"please enter something xp"<<endl;
    cin.get(xp);
    cout<<xp<<":::blab"<<endl;
    }

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    ok that didnt work.......what was that last ::blab line?

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    it worked

    If you want a string then use getline functin and make it char *

    Thanks

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    i want the user to be able to enter a string but for the program to access that string one character at a time. the exact same thing as getting characters from a file using in_stream.get(next) except getting them from the user. i tried what yous ent in my program but it didnt work. what was that last ::blab line doing?

  8. #8
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
          char bob[256];
          cout << "enter the true name of god!" << endl;
          cin >> bob;
          for (int i = 0; bob[i] != 0; i++)	cout << bob[i];
          cout << endl<< "how dare you call his name!"<<endl;
    }
    //just kiding!

    blab stuff means blablabla... its nothing!
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21