473,785 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getl ine(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_ifst ream<char, std::char_trait s<char> >::basic_ifstre am(
std::string&)'
/usr/lib/gcc-lib/i386-pc-linux-gnu/3.3.2/include/g++-v3/iosfwd:89:
error: candidates
are: std::basic_ifst ream<char, std::char_trait s<char>
::basic_ifstre am(const std::basic_ifst ream<char,

std::char_trait s<char> >&)
/usr/lib/gcc-lib/i386-pc-linux-gnu/3.3.2/include/g++-v3/fstream:519:
error:
std::basic_ifst ream<_CharT, _Traits>::basic _ifstream(const
char*, std::_Ios_Openm ode) [with _CharT = char, _Traits =
std::char_trait s<char>]
/usr/lib/gcc-lib/i386-pc-linux-gnu/3.3.2/include/g++-v3/fstream:504:
error:
std::basic_ifst ream<_CharT, _Traits>::basic _ifstream()
[with
_CharT = char, _Traits = std::char_trait s<char>]
Jul 22 '05 #1
4 3774
On Sun, 11 Apr 2004 01:36:16 GMT, Lingyun Yang <yz***@insightb b.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.get line(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***@insightb b.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.get line(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***@insightb b.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***@insightb b.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
5271
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" (?myVersion@TextDB@1@0PADA) My environment is Visual Studio .NET, I think it's C++ 7 from the microsoft visual studio versioning point of view. Here is TeXt.h:
4
376
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
2755
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
4928
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 give me the error "Unable to write to memmory." This is a static function that receives a string that is the name of a file and an ifstream pointer. It then concatenates the path string using the string.h function strcat(char *, const char *) and...
6
1742
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
4862
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 result of pstack for the core dump is > pstack core | c++filt
7
3645
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&)' collect2: ld returned 1 exit status
2
5300
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 forum but can't find an answer. I hope that someone can help :-) test.h: #include <iostream> #include <fstream> #include <string> using namespace std; class ReadFile
2
5900
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 matter what modifications I make, I get an error, "line 42: Error: Could not find a match for std::basic_istream<char, std::char_traits<char>>::get(int)." I have tried everything I can think of. Help? #include <iostream> #include <fstream>
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.