How can I include punctuation in a string?

This is a discussion on How can I include punctuation in a string? within the C++ Programming forums, part of the General Programming Boards category; This seems simple, but I can't get it to work. I'm writing a simple compiler program in VC++ 6. I'm ...

  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,801
    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, 10:03 PM
  3. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 11:47 AM
  4. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21