473,770 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ifstream / ofstream question (using libstdc++ v3)

How can i read a numbers from file.. I created this file like this:

int dane, i;
std::ofstream plik_z;
plik_z.open(naz wa, std::ios::out | std::ios::trunc | std::ios::binar y);
for (i = 0; i < 15; i++) plik_z << dane;
plik_z.close();
Is it any way to read from this file all numbers ?.. If so - how can i do
it.
If it's impossible - how should i create this file to be able to read a
numbers from this file?
I couldn't find any formatted input / output functions in ifstream /
ofstream.

phoenix.
Jul 22 '05 #1
1 1632
phoenix wrote:
How can i read a numbers from file.. I created this file like this:

int dane, i;
std::ofstream plik_z;
plik_z.open(naz wa, std::ios::out | std::ios::trunc | std::ios::binar y);
for (i = 0; i < 15; i++) plik_z << dane;
You probably need to put some kind of separator between the numbers
you output. Use a space, for example:

... plik_z << dane << ' ';
plik_z.close();
Is it any way to read from this file all numbers ?..
Yes. Open another stream of type 'std::ifstream' . Then use operator >>
to read the numbers. It will automatically skip the spaces.
If so - how can i do
it.
If it's impossible - how should i create this file to be able to read a
numbers from this file?
See above.
I couldn't find any formatted input / output functions in ifstream /
ofstream.


Functions called 'operator<<' and 'operator>>' are for output and input.

What C++ book are you reading that doesn't explain that?

Victor
Jul 22 '05 #2

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

Similar topics

2
4061
by: Armando | last post by:
i write one programm in vc++ but the compiler say that i use ambiguous symbol,i don´t know why ? how can do to tell the compiler that is ok so ? i become this error message: error C2872: 'ifstream' : ambiguous symbol error C2872: 'ofstream' : ambiguous symbol error C2065: 'fileread' : undeclared identifier error C2228: left of '.open' must have class/struct/union type error C2228: left of '.eof' must have class/struct/union type
1
1683
by: tom | last post by:
have seen a few posts about this but no solutions. files larger than 2Gb don't open with ifstream.open ie. #include <fstream> int main(in argc, char** argv){ ifstream in ; in.open("3GBfile");
8
4751
by: Jing Cheng | last post by:
Hi, I'm using ifstream reading data from a file, as following: ifstream finput("track.dat"); if(finput.fail()){ cerr << "Open input DATA file error!\n"; exit(-1);
7
7556
by: shawn | last post by:
Hi All, Am using MSVC6 compiler on a WinXP machine. Am trying to read a file using std::ofstream; the problem is that Tofstream.is_open() fails and Tifstream.rdstate() returns "2" which translates to "The system cannot find the file specified.". This is really weird because the said file am tring to read exists on the disk at the required location. SNIPPET:-
2
14091
by: Karl | last post by:
Hey everyone! I've got a quick question on whether std::ifstream is buffered or not. The reason is that I have a homework assignment that requires me to benchmark copying files using different buffer sizes. I ended up doing this using std::istream::readsome() and std::ostream::write(): // now try writing to the destination file std::ifstream sourceStream(sourceFilename.c_str(), std::ios::binary);
4
4746
by: manontheedge | last post by:
i'm working on a C++ program that uses operator overloads (which i'm just learning to use), and i have the ostream working fine, but i'm thinking i'm using it wrong somehow because the ofstream doesn't work. Here's some code fragments... class matrix { public: ...... friend ostream& operator << ( ostream& os, matrix& m );
4
12870
by: marathoner | last post by:
I tried your advice, and replaced "ifstream" with "std::ifstream". I also replaced instances of "ofstream" with "std::ofstream". Those syntax errors were resolved. When I added "std" to the following statement: m_InFile.open(m_sFileName, ios::in | ios::binary); which became m_InFile.open(m_sFileName, std::ios::in | std::ios::binary); I get the following errors:
6
4762
by: Gary Wessle | last post by:
hi I have a code, the part which is troubling goes like this **************************************************************** #include <istream> #include <ostream> #include <fstream>
11
8147
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream fails to open a file, but nothing I read about ifstream says anything about a reliable place to get an error message. Using stdio I can simply do: FILE *f = fopen(filename, "rb"); if (!f) perror(filename);
0
9617
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
9454
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
10257
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
10099
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
10037
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
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
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...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
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.