Click here to Skip to main content
15,888,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionreading values within std::list types Pin
jon-8026-Aug-06 8:34
professionaljon-8026-Aug-06 8:34 
AnswerRe: reading values within std::list types Pin
Waldermort26-Aug-06 9:23
Waldermort26-Aug-06 9:23 
GeneralRe: reading values within std::list types Pin
jon-8026-Aug-06 10:40
professionaljon-8026-Aug-06 10:40 
GeneralRe: reading values within std::list types Pin
Waldermort26-Aug-06 10:53
Waldermort26-Aug-06 10:53 
AnswerRe: reading values within std::list types [modified] Pin
Mike Danberg27-Aug-06 17:53
Mike Danberg27-Aug-06 17:53 
QuestionOperating system info Pin
Kiran Pinjala26-Aug-06 8:29
Kiran Pinjala26-Aug-06 8:29 
AnswerRe: Operating system info Pin
Mike Dimmick26-Aug-06 9:47
Mike Dimmick26-Aug-06 9:47 
Questionconverting str::string to const char* Pin
jon-8026-Aug-06 8:03
professionaljon-8026-Aug-06 8:03 
The following code should read a text file and update Sentences (defined as std::list<string> Sentences).

However, fstream does not seem to like 'string' types. Is it possible to retain string types and convert it to char?

bool CSentenceList::readFile(const string strFileToRead)
{
string strLine;

fstream fileToRead((char*) strFileToRead,ios::in);

if (ios::good != false)
{while (!fileToRead.eof() && Size < MAX_LINES)
// Read line of text from file and update Sentences.strSentence.
{ fileToRead.getline(strLine, MAX_SENTENCE_LENGTH);
Sentences.push_back(strLine);
Size++;
}
return true;
}
else
{ throw "File cannot be read!";
return false;
}

fileToRead.close();
}

Errors:

SentenceList.cpp(23): error C2440: 'type cast' : cannot convert from 'const std::string' to 'char *'

SentenceList.cpp(28): error C2664: 'std::basic_istream<_Elem,_Traits>::_Myt &std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::string' to 'char *'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]



Are there other objects I can use so I can read text files from 'string' types, since they are less prehistoric?

Jon
AnswerRe: converting str::string to const char* Pin
Pierre Leclercq26-Aug-06 8:34
Pierre Leclercq26-Aug-06 8:34 
GeneralRe: converting str::string to const char* Pin
Pierre Leclercq26-Aug-06 9:29
Pierre Leclercq26-Aug-06 9:29 
AnswerRe: converting str::string to const char* Pin
Waldermort26-Aug-06 8:59
Waldermort26-Aug-06 8:59 
GeneralRe: converting str::string to const char* Pin
fefe.wyx26-Aug-06 15:59
fefe.wyx26-Aug-06 15:59 
QuestionLoading drivers programmatically Pin
Still learning how to code26-Aug-06 6:58
Still learning how to code26-Aug-06 6:58 
AnswerRe: Loading drivers programmatically Pin
Gary R. Wheeler26-Aug-06 12:28
Gary R. Wheeler26-Aug-06 12:28 
GeneralRe: Loading drivers programmatically Pin
Still learning how to code27-Aug-06 1:42
Still learning how to code27-Aug-06 1:42 
Questionunicode strings Pin
Waldermort26-Aug-06 5:42
Waldermort26-Aug-06 5:42 
AnswerRe: unicode strings Pin
fefe.wyx26-Aug-06 6:32
fefe.wyx26-Aug-06 6:32 
GeneralRe: unicode strings Pin
Waldermort26-Aug-06 7:06
Waldermort26-Aug-06 7:06 
GeneralRe: unicode strings Pin
Pierre Leclercq26-Aug-06 8:55
Pierre Leclercq26-Aug-06 8:55 
GeneralRe: unicode strings Pin
Waldermort26-Aug-06 9:04
Waldermort26-Aug-06 9:04 
GeneralRe: unicode strings Pin
Pierre Leclercq26-Aug-06 9:49
Pierre Leclercq26-Aug-06 9:49 
GeneralRe: unicode strings Pin
Justin Tay26-Aug-06 10:08
Justin Tay26-Aug-06 10:08 
AnswerRe: unicode strings Pin
Mike Dimmick26-Aug-06 10:51
Mike Dimmick26-Aug-06 10:51 
GeneralRe: unicode strings Pin
Waldermort26-Aug-06 11:02
Waldermort26-Aug-06 11:02 
AnswerRe: unicode strings Pin
Michael Dunn26-Aug-06 21:37
sitebuilderMichael Dunn26-Aug-06 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.