473,803 Members | 3,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A complete solution

Hi Tad,

While learning to use streams with a simple parse such as this my
opinion is that you don't need the complication of a splitting
function, vectors, etc. When you extract number types (int,float,...)
from the stream it will read all appropriate digits and stop at
characters such as a comma. Therefore, you can simply extract the
number and then the separator. Here is a complete solution that writes
the transformed string to standard out :

#include <fstream>
#include <iostream>

int main ( int argc , char * argv[] {

std::ifstream input ( "AA.ASC" ) ;

int itemp ;
char comma ;
double ftemp ;

input >> itemp ;
std::cout << "AA," << itemp ;

std::cout.preci sion ( 2 ) ;
std::cout.flags ( std::ios::fixed ) ;

for ( int i = 0 ; i < 4 ; ++i ) {

input >> comma >> ftemp ;
std::cout << comma << ftemp ;

}

input >> comma >> itemp ;
std::cout << comma << itemp ;

return 0 ;

}

In this case I hard-coded the file name and output stream but of
course in the future you will probably want to improve upon this.
Also, it differs slightly from your requirements because streams ROUND
the decimal rather than truncating it. I figured that's probably what
you actually wanted; but, if you really want to truncate then alter
the code as follows :

input >> comma >> ftemp ;
ftemp = 0.01 * int ( 100.0 * ftemp ) ; // truncate instead of
round
std::cout << comma << ftemp ;

or better :

input >> comma >> ftemp ;
ftemp = 0.01 * static_cast<int > ( 100.0 * ftemp ) ;
std::cout << comma << ftemp ;
Jul 22 '05 #1
1 1338
Sorry, this message was meant as a follow up to the thread :

"Help for a Pascal programmer please?"
Jul 22 '05 #2

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

Similar topics

12
15927
by: Anders Eriksson | last post by:
Hello! I'm trying to create a program that will watch a directory and when a file is created print that file. I have used FileSystemWatcher for watching the directory and I get an created event. The problem is that I don't know when the file is complete when using Explorer copy or move. I have tried to use FileIOPermission but I always get that the file is
4
1806
by: gabe | last post by:
i have a solution to gather the text in each window that is open, but would rather use only managed code rather than unmanaged code my current solution relies on. The purpose is to get the text in each open window even/especially for child windows in other non managed mdi apps - if excel has 3 books open or any other mdi app has several windows open, I'd like the complete text from each window. The current solution gives me more info...
6
2356
by: Smithers | last post by:
I am looking to implement a search feature into a Windows Forms MDI application. Specifically I plan to embed 3 textboxes into a toolbar; one for LastName, another for FirstName, and one for CustomerID. When the user starts typing into any of these textboxes I would like to pop up another form that shows the user a dynamic list of the closest matches. The user can then use the up- and down-arrow keys to select a customer from that pop up...
8
2603
by: Andreas R. | last post by:
Hi again, I'm using Python's asynchat module for networking. When calling the sendall() method of asynchat, I sometimes get the error message "the operation could not complete without blocking". So how do I enable blocking with synchat, or otherwise fix this error? Thanks for the help I've received with asynchat so far in this news group.
5
2222
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only parts of your page. But in my application there are situation when I first notice on the server -- so AFTER sending an AJAX request -- that I have to update the complete page instead of only some parts. And what do I do now???
2
5421
by: RobG | last post by:
There has been a bit of work done to get an init() function to run when the DOM is complete but before all the images have been downloaded. The idea is to kickoff init() scripts when all the elements are there but not wait for large images. Below is a script which uses 3 different techniques, one each for IE, Safari and Mozill/Opera 9. The Safari version uses browser sniffing, but I think with a little work that could be removed - the...
2
9550
by: barthelemy.von.haller | last post by:
Hi all, I googled and read this group but could not find any solution to my problem. I have a page to download big excel files that we 'build' on the server side. When a user click on the link to download, he has no clue that something is going on (and it can take some time). Indeed if the cursor is over some text or some special parts of the page it will not be set to the 'progress' type.
2
1414
by: =?Utf-8?B?UmFmYWVsIFNvdGVsZG8=?= | last post by:
Hi there: Does anybody know where can I find a good and complete C# Solution Developing Guidance. With subjects like: * What's the best place for Global Objects and Global Variables * Naming Conventions * Solution arquitecture that help code reuse
0
1885
by: henry | last post by:
Folks: Thank you all for your replies. I'll reply briefly to each key point: Thanks! You are probably correct. I wanted to be aware of other options, that's all. Part of what got me in this mess is not finding out enough before I jumped in.
0
9565
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
10550
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...
1
10295
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
10069
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
9125
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
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
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.