CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: C# To C++

  1. #1
    Join Date
    Jun 2012
    Posts
    6

    C# To C++

    This is nothing big, but i dont understand anything from C++

    Could you translate this code to C++ please?
    File.WriteAllText(@"test.txt", Regex.Replace(Regex.Replace(File.ReadAllText(@"test.txt"), @"-?(?<!,|\d)(?>\d+)(?!,)", "($&)"), @"-?\d+,\d+", "\"$&\""));

  2. #2
    Join Date
    Oct 2011
    Posts
    97

    Re: C# To C++

    The rough overview is that it's reading in a file, doing a regular expression find and replace, then writing that data back to the file. It really should be broken into a few different lines to be more understandable. I don't know what version of VS you're using, but if you have 2008 or above, you can use TR1 regular expressions for that. And you can always use good old fopen, fread and fwrite for the File IO. (There's plenty of libraries to use though. I'm pretty sure MFC has a CFile class or something.)

    I suggest acquainting yourself with C++ first. And not asking people to just 'translate' code for you. We're here to help, not to do the work for you.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C# To C++

    Quote Originally Posted by edelis View Post
    This is nothing big, but i dont understand anything from C++
    You don't understand C++, but you assume it's "nothing big". Also, if you don't understand any C++, what were you going to do with the C++ code (if it were to be translated)?

    That one line requires knowledge of C++ file I/O and proper usage of a regular expression library, whether it is <regex> or some other third-party library. To discuss this further in detail is too much for a simple forum response.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Jun 2012
    Posts
    6

    Re: C# To C++

    Yes, i know what to do with code, but could you please give it to me?

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: C# To C++


  6. #6
    Join Date
    Jun 2012
    Posts
    6

    Re: C# To C++

    ???

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C# To C++

    Quote Originally Posted by edelis View Post
    ???
    What's the problem? You were given a link to C++ code that processes a regular expression. As a matter of fact, it is a full example of usage of the class.

    Did you think that one line of code in C# means one line of code in C++?

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured