CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,100

    Re: simple log functionality

    Quote Originally Posted by pdk5 View Post
    @GCDEF: thanks a lot

    Sorry for so many q's, but my initial question, was trying to comeup with logger.

    But now i just want to try a simple text file. But the issue is, if the input directory path is "forward slash", ofstream creats/opens file propely, even in windows. But in my case, input string is windows format..i.e backslash. i want to convert the file path

    std::string filepath= C:/temp

    to file std::string filepath=C:\temp

    basically, tried to use std::replace is not working... any help is much appreciated
    It's very simple! in this string
    Code:
    "C:\temp\test.log"
    there is NOT any backslash! There are instead two TAB symbols:
    Code:
    "C:TABempTABest.log"
    Victor Nijegorodov

  2. #17
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,553

    Re: simple log functionality

    Code:
    Logger l { "C:\temp\test.log" };
    In Windows, you need to specify \\ to separate names

    Code:
    Logger l { "C:\\temp\\test.log" };
    or specify a raw string

    Code:
    Logger l { R"(C:\temp\test.log)" };
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.11.5)

  3. #18
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,624

    Re: simple log functionality

    Quote Originally Posted by pdk5 View Post
    @GCDEF: thanks a lot

    Sorry for so many q's, but my initial question, was trying to comeup with logger.

    But now i just want to try a simple text file. But the issue is, if the input directory path is "forward slash", ofstream creats/opens file propely, even in windows. But in my case, input string is windows format..i.e backslash. i want to convert the file path

    std::string filepath= C:/temp

    to file std::string filepath=C:\temp

    basically, tried to use std::replace is not working... any help is much appreciated
    I told you why replace isn't working.
    https://en.wikipedia.org/wiki/Escape_sequences_in_C

    I'm still not sure why you don't write the backslashes in the first place, or if forward slash works, why you want to change it.

Page 2 of 2 FirstFirst 12

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