Thread: How can I include punctuation in a string?

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    9

    How can I include punctuation in a string?

    This seems simple, but I can't get it to work. I'm writing a simple compiler program in VC++ 6. I'm trying to define three strings that will be checked by my parser to make sure they are syntactically correct. The problem is, I'm not sure how to include semicolons and parentheses in a string. The program compiles, but crashes when run.

    Here are the three inputs:
    Code:
    	
    #include <string>
    using namespace std;
    
    int main()
    {
    
    string input1 = "i+i+i;";
    string input2 = "i/n;";
    string input3 = "(i*i+i*i+i*i);";
    	
    return 0;
    }
    I've tried escaping the semicolons and parentheses, but the program still crashes.

    Code:
    	
    string input1 = "i+i+i\;";
    string input2 = "i/n\;";
    string input3 = "\(i*i+i*i+i*i\)\;";
    Thanks for the help!

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    That code works for me are you sure you are not doing something else?
    Woop?

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    13
    what compiler are you using? it compiles and runs fine for me on Dev-C++ 4.9.8.0...

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    9
    Ha! My bad. It was something else causing the crash. Thanks for the responses, that helped to locate the problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  4. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM