473,770 Members | 3,398 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 3772
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
2751
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
4927
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
1741
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
4861
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
5899
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
9591
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
9425
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
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10057
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...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
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
7415
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...
1
3970
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
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.