string to character problem--maybe?

From: Darrell (mcdougal48_at_cox.net)
Date: 02/09/05


Date: Tue, 8 Feb 2005 23:43:17 -0800

I need to open a number of files. I want to be able to change the
name of the file in the program.

#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<sys/types.h>
#include<stdio.h>

#using <mscorlib.dll>
using namespace std;
int _tmain()
 {
 string filename;
 string cc[8031];

 // *********** Open Input File

// I want to be able to replace aapl.csv with ibm.csv dal.csv etc.
//I do this by reading the names from a file
// I have already created.

 filename = "c:\\stkdata\\aapl.csv";
 ifstream file_in;

// If I use this line, the program runs
 file_in.open("c:\\stkdata\\aapl.csv");

//If I us this line, the program aborts
 file_in.open(filename);

//I want to be able to change filename on the fly

// this is the error message I get
//readtxt.cpp(25): error C2664:
 'void std::basic_ifstream<_Elem
,_Traits>::open(const char *,std::_Iosb<_Dummy>::openmode,int)'
 : cannot convert parameter 1 from 'std::string' to 'const char *'

// with
// [
//
           _Elem=char,
// _Traits=std::char_traits<char>,
// _Dummy=int
// ]

//Any suggestions greatly appreciated



Relevant Pages

  • Reading a file byte by byte
    ... I'm trying to do a Hex Viewer in C#. I'm reading the user selected ... file byte by byte but it seems to take forever (one minute to read a ... string fileName = openFileDialog.FileName; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Unicode and such
    ... >File doesn't take a (String filename, ... The file class has nothing to do with contents or reading or writing. ... In nio look at the Charset, ...
    (comp.lang.java.programmer)