Thread: Strings and Whitespace

  1. #1
    Unregistered
    Guest

    Post Strings and Whitespace

    anyone have a way to take a string of unknown length and break it up using the spaces (white space) that are in it?

    data example: president john jones, iii

  2. #2
    Unregistered
    Guest
    look at tokenising function, strtok(...) I think in <cstring>/<string.h>

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Using the CString class would be the easiest way.
    http://msdn.microsoft.com/library/de.../cstring_1.asp

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    anyone have a way to take a string of unknown length and break it up using the spaces (white space) that are in it?

    data example: president john jones, iii
    Code:
    #include <sstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	istringstream text("president john jones, iii");
    	string word;
    	while(text >> word)
    		cout << word << '\n';
    }
    - lmov

  5. #5
    Unregistered
    Guest
    Originally posted by Dual-Catfish
    Using the CString class would be the easiest way.
    http://msdn.microsoft.com/library/de.../cstring_1.asp
    I believe CString is only available in MFC, or otherwise difficult to get.

  6. #6
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Are you sure? I think you can either include cstring.h or windows.h and use it..
    I don't see how you'd need MFC to use it..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 06-10-2008, 02:17 AM
  2. Need some help with strings
    By aldin176 in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2006, 02:13 PM
  3. Strings
    By krithi in forum C Programming
    Replies: 3
    Last Post: 12-25-2002, 05:54 PM
  4. ignoring whitespace with fscanf
    By Viny in forum C Programming
    Replies: 1
    Last Post: 11-22-2001, 04:05 PM
  5. slipped my mind ... cleaning up strings
    By edk in forum C++ Programming
    Replies: 5
    Last Post: 09-07-2001, 12:49 PM