CString for ifstream

Posted on 2006-05-23
Last Modified: 2013-11-20
I have a cstring which contains the path to the file I want to use.

So fill in the blank what I should put here.

ifstream in(BLANK);

I've tried GetBuffer and it complained.  I tried casting to LPCTSTR and it complained.
Question by:cophi
    LVL 48

    Expert Comment

    How exactly does it complain?

    Author Comment

    error C2440: 'initializing' : cannot convert from 'ATL::CSimpleStringT<BaseType,t_bMFCDLL>::PCXSTR' to 'const char *'
    LVL 48

    Accepted Solution

    If your project is Unicode, you can use wifstream instead of ifstream.
    LVL 48

    Expert Comment

       CString s;
        ifstream in(s);

        CString s;
        wifstream in(s);

    Both versions are compiled in my VC++ 8.0.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now