473,378 Members | 1,429 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,378 software developers and data experts.

Input floats from command line using streams

Hello There

My first question on this site, here goes:

I am working on a tutorial question and it asks me to write a program that outputs the product of some entered floating point numbers from the command line: This is to be done using streams.
Now in My tutorial book it suggests using the following code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <fstream>
  7. #include <string>
  8. #include <cstdlib>
  9. #include <istream>
  10. using namespace std;
  11.  
  12. int main(  int argc, char* argv[] ) 
  13. {  
  14.  
  15.           int data[20];
  16.           int i, sum;
  17.  
  18.           for(i=1;i<argc-1;i++){
  19.  
  20.               istream cinx(81,argv[i];
  21.  
  22.               cinx>>data[i];
  23.               cout<<data[i];
  24.  
  25.               sum=sum+data[i];
  26.          }
  27.          cout<<"\nsum = "<<sum;
  28. }
  29.  
So I have tried the above code and many different variations until my hair is falling out! - But to no avail as it does not compile, instead I get the error message along the lines of:

" no matching function for call to `std::basic_istream<char, std::char_traits<char> >::get(char**&, int)"

Any suggestions would be much appreciated...

Regards

leigh
Oct 13 '11 #1
1 2074
weaknessforcats
9,208 Expert Mod 8TB
This code:
Expand|Select|Wrap|Line Numbers
  1. for(i=1;i<argc-1;i++){
  2.  
  3.      istream cinx(81,argv[i];
  4. etc...
is a problem.
First, argc is the number of command line argumen ts and not the number of strings in the argv array.
Second, you check for the end of the argv array by looking for a string that contains only two null characters.
Third, you don't need to use cin on argv since you already have the address of the array. All you have to do is process it.

Unless...
the object is for the user to enter floats from the keyboard as the program runs. Then you would use cin.
Oct 13 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: me | last post by:
I have been looking online for a year, and cant find one. I used to use the int86() command in dos command-line mode, but it can't work in linux. I am using Allegro to make my program work, but I...
0
by: mark lawler | last post by:
Ok, for my assignment all my classes are working now *hooray* and all I need to do is set up the reading from the command line so the user can input commands. Im using getline and a stringstream...
6
by: Robert Dobson | last post by:
In Java you can execute a single class from the command line using the command: java.exe <classname> As long as the class in question has a method declared as "public static final main(...
8
by: djc | last post by:
I'm new to this and was wondering what the options are for interpreting the command line using a CLI program. Specifically methods for interpreting the parameters passed to the program on the...
6
by: evantri | last post by:
I am developing a program that prompt the input from the command line argument. For example, this is the lists of command line arguments that I want to include: -fish -cat -dog -animal All...
2
by: ttan | last post by:
I'm using c# to called a command line netsh ipsec static.... and the group policy store it on local even those I used "ipsec static set store location=domain" my question is how do I keep the...
0
by: chandan agarwal | last post by:
hi I have been given the task of building vc++ programs at the command line using make software. i have installed gnu make-3.81 version. i was able to build and run makefiles for turbo c++. but...
2
by: achinm | last post by:
Hi, I need to send a mail using Outlook with an attachment, using DOS / Command Line. The line of code i am using is \outlook.exe /c ipm.note /m enmail@sender.com /a C:\attachedFile.txt ...
9
by: bu0461 | last post by:
Hi this is my first post! I'm currently learning C programming language and have just finished structure section. At this point I think I'm able to program some very basic text command line games....
3
by: smitty1e | last post by:
Just a fun exercise to unify some of the major input methods for a script into a single dictionary. Here is the output, given a gr.conf file in the same directory with the contents stated below: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.