Results 1 to 5 of 5

Thread: i/o

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Question

    How do I read an entire string when i use cin. The problem is that cin stops reading at the first white space. One other thing. How come when I go to open a file using fopen I have to type the path in with the '/' instead of say C:\ i use C:/. Thanks
    Last edited by MPrestonf12; Feb 27th, 2001 at 07:38 PM.
    Matt

  2. #2
    Lively Member
    Join Date
    Sep 2000
    Location
    Singapore
    Posts
    78

    Talking

    You should write cin in this syntax:

    cin.getline(str1, 30, '\n');

    Where str1 is the string name, 30 is the length of characters u wish to read, and the last parameter, will stop reading after reading in a Nextline (you can set any characters to be the terminator here).

    Hope this helps

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    would you happen to know the header needer for that? Thanks
    Matt

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's in <iostream>:
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void main() {
        string sInput;
    
        cin.getline(sInput, 30, '\n');
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    great, thanks!
    Matt

Posting Permissions

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



Click Here to Expand Forum to Full Width