473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

error when initialize ifstream with string

hi every one,

I meet a compile error in my small homework program:
Can I innitialize ifstream with a string?
or I must come back to char* style string?
Thank you!

Lingyun
//----------- here is part of my small program ---------------
string dicname("tofel.bok.gb2312");

char buf[256];
ifstream fdic(dicname);
while(fdic.getline(buf,256))
{}

//---------------- Here is the compile error ------------------
/home/lyyang/cpp-proj/wordwar.cpp: In function `int main()':
/home/lyyang/cpp-proj/wordwar.cpp:29: error: no matching function for
call to `
std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(
std::string&)'
/usr/lib/gcc-lib/i386-pc-linux-gnu/3.3.2/include/g++-v3/iosfwd:89:
error: candidates
are: std::basic_ifstream<char, std::char_traits<char>
::basic_ifstream(const std::basic_ifstream<char,

std::char_traits<char> >&)
/usr/lib/gcc-lib/i386-pc-linux-gnu/3.3.2/include/g++-v3/fstream:519:
error:
std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const
char*, std::_Ios_Openmode) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc-lib/i386-pc-linux-gnu/3.3.2/include/g++-v3/fstream:504:
error:
std::basic_ifstream<_CharT, _Traits>::basic_ifstream()
[with
_CharT = char, _Traits = std::char_traits<char>]
Jul 22 '05 #1
4 3732
On Sun, 11 Apr 2004 01:36:16 GMT, Lingyun Yang <yz***@insightbb.com> wrote:
hi every one,

I meet a compile error in my small homework program:
Can I innitialize ifstream with a string?
or I must come back to char* style string?
The fstream constructors do require a char* style string, but fortunately
it is trivial to get one from a std::string: just apply the c_str() member
function, e.g.:
ifstream fdic(dicname.c_str());
-leor



Thank you!

Lingyun
//----------- here is part of my small program ---------------
string dicname("tofel.bok.gb2312");

char buf[256];
ifstream fdic(dicname);
while(fdic.getline(buf,256))
{}


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
On Sun, 11 Apr 2004 01:36:16 GMT, Lingyun Yang <yz***@insightbb.com> wrote:
hi every one,

I meet a compile error in my small homework program:
Can I innitialize ifstream with a string?
or I must come back to char* style string?
The fstream constructors do require a char* style string, but fortunately
it is trivial to get one from a std::string: just apply the c_str() member
function, e.g.:
ifstream fdic(dicname.c_str());
-leor



Thank you!

Lingyun
//----------- here is part of my small program ---------------
string dicname("tofel.bok.gb2312");

char buf[256];
ifstream fdic(dicname);
while(fdic.getline(buf,256))
{}


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3
On Sun, 11 Apr 2004 01:36:16 GMT in comp.lang.c++, Lingyun Yang
<yz***@insightbb.com> wrote,
ifstream fdic(dicname);


ifstream fdic(dicname.c_str());
Jul 22 '05 #4
On Sun, 11 Apr 2004 01:36:16 GMT in comp.lang.c++, Lingyun Yang
<yz***@insightbb.com> wrote,
ifstream fdic(dicname);


ifstream fdic(dicname.c_str());
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kevin Grigorenko | last post by:
Okay, everything seems simple enough but I get the following Link error: TeXt.obj : error LNK2001: unresolved external symbol "private: static char * TextDB::TextDB::myVersion"...
4
by: Lingyun Yang | last post by:
hi every one, I meet a compile error in my small homework program: Can I innitialize ifstream with a string? or I must come back to char* style string? Thank you! Lingyun
6
by: Kai Wu | last post by:
#include <string.h> #include <fstream> #include <time.h> typedef unsigned char BYTE; struct Dex { BYTE status; struct timeval timestamp; }; int main(){
7
by: mattsniderppl | last post by:
Hi, i'm relatively new to C++ from java and am having a difficult time with pointers. I'm sure there is something simple that I am doing wrong, but I can't seem to write this in a way that doesn't...
6
by: Baloff | last post by:
Hello I wrote a code which is suppose to read a file which contains lines of double and prints it out. thanks for helping double.txt*************************************** 1.01 2.0301
4
by: wqyuwss | last post by:
Hi, We have several core dumps in our product. These core dump can be reproduced in the same place. That is system function call std::basic_istream<char,std::char_traits<char>>::getline. The...
7
by: gdarian216 | last post by:
im getting an error and I dont know why can anyone help. this is the error...... /tmp/ccxaenRY.o(.text+0x375): In function `main': : undefined reference to `average_quizes(records, float&)'...
2
Schwack
by: Schwack | last post by:
I've just started learning C++ (got bored at work) and I'm using VC++ to compile some simple code but I get a compile error in test.cpp when using "getline". I've searched the internet and this...
2
by: Sejoro | last post by:
Hello, I am trying to write a program that opens a file; reads through it; outputs the text; then outputs the number of lines, words, and characters. Problem is, every time I try to compile, no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.