Thread: String array and spaces:

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by jocdrew21 View Post
    in java I just wrote card[]=hand.split(" "); then just iterated cards[] 0-4 and 5-9 to set each players hand. I suppose I way of thinking on how to tackle this is the issue.
    You can do that in C++ too, but the way you were doing it was not splitting the string.
    Just for reference, one way to do this (except with stringstream as you found out) is with boost (the standard library conveniently lacks a splitting function):

    std::vector<std::string> Output;
    boost::split(Output, Input, boost::is_any_of(" "));

    Btw, stringstream is a stream, and getline takes a stream. The std::*fstream family are also streams.
    Therefore, you can get easily apply getline directly when reading a file:

    std::getline(File, Line, " ");
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    499
    I tried to do that but I was only able to be ' ' to work and not " "

    I would love to use boost but I cannot figure out how to get it loaded onto Xcode 5.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by jocdrew21 View Post
    I tried to do that but I was only able to be ' ' to work and not " "
    You're right. It should be ' ', not " ". I type things out of memory and sometimes I forget.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 12-04-2010, 12:04 AM
  2. Replies: 7
    Last Post: 10-03-2009, 10:58 PM
  3. String with Spaces. HELP.
    By tanpearl in forum C Programming
    Replies: 3
    Last Post: 02-20-2009, 08:49 AM
  4. Can a String Have Spaces In It?
    By Grantyt3 in forum C++ Programming
    Replies: 6
    Last Post: 08-28-2005, 09:49 AM
  5. Getting rid of spaces in a string
    By scythe in forum C Programming
    Replies: 3
    Last Post: 10-23-2003, 04:05 AM