Thread: <space> delimiter in string class causes program to crash when " " charachter is ent

  1. #1
    Registered User
    Join Date
    Oct 2002

    Question <space> delimiter in string class causes program to crash when " " charachter is ent

    I am trying to run a standard win32 console application, e.g. simple "Hello World" style app just to test this stupid "bug" or whatever it is.

    Does anyone know how to use the cin >> statement to store a " " character into a string variable


    #include <iostream>
    #include <string>
    using namespace std;

    void main ()
    string somestring;
    cin >> somestring;
    cout << somestring;
    char somechar;
    cin >> somechar;

    when the cin statement asks for text it will go fine unless a space is entered into the string. When a space is present hitting enter after the string crashes the program and it does not even run the cout statement. There is no error, it just exits. I tried it with a character array too and it did the same thing.

    I am using Microsoft Visual through my school and it is a horrible program. I see source code all the time where this problem isn't an issue, should i switch compilers?
    Any Suggestions?

  2. #2
    Registered User
    Join Date
    Dec 2001
    use int main()
    not void
    try cin.getline()
    instead of cin>>
    try msvc++6

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Göteborg, Sweden
    It doesn't crash, it just exits main() normally after reading one string and one char.

    cin >> stops reading at a whitespace.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. Runtime error in Class, string based program.... plz help
    By PotitKing in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2001, 08:15 AM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM