473,409 Members | 1,952 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,409 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 3736
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.