Thread: Unsized string input

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    6

    Unsized string input

    Hi (btw, I'm new in this Forum)

    I'm doing a project and I have a problem with strings and char arrays (mainly because of the limited size, but also some other stuff).
    I'm not sure if I need to put here the code I've done, since it's mainly small stuff, but I'll do it if you find the need.

    In the program I need to open a text file chosen by the user, so I put an ifstream. Problem is: I'd like the user to be able to input an unlimited char array by a simple

    cout<< "Path to file: ";
    cin>> Path;

    or something like this...
    I tried with strings (getline) and then converting it to a char array (cause ifstream only accepts the path in char array), but for some reason the program stopped once I got to the getline part (I used "getline (cin, Filename)"). I searched for the reason, couldn't find it, tried another way.
    Right now I just have:

    char Path[200]

    cout<< "Path to file: ";
    cin>> Path;

    but it will only read until it finds a " " (if I'm not wrong).

    Later, there's another problem, but it's similar so, once I find a solution for that one, the other one is probably solved.

    (In the project, I'm going to take the text from the text file, put it to a string and then pass it to a linked list... any suggestions about that would be greatly apreciated.
    Also, I'm on my first year with Programming, so please don't get too complicated.)

    Thanks in advance.
    Last edited by DsH; 07-13-2009 at 03:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Replies: 14
    Last Post: 01-18-2008, 04:14 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Basic C Programming Help Needed
    By Smurphygirlnz in forum C Programming
    Replies: 8
    Last Post: 09-26-2002, 07:12 PM