Jump to content
  • Advertisement
Sign in to follow this  
theBegger

Print string in two pieces

This topic is 1595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ACCIDENTAL EXTRA CODE BOX?
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string> 
using namespace std; 

//Global struct   
struct component
 {
   int mant;                
   double exp;                          
 };

//Function Prototypes
void readCharacters(component& function)                    //OUT:Data destination
 {
     string scientificNotation;

     cout << "\t\t\tScientific Notation Calculator\n\n";
     cout << "Please enter a number in scientific notation.\n";
     cout << "For Example: -0.1234E20\n";
     getline(cin, scientificNotation, 'E' && 'e');
     function.mant = cin.get();
     cout << "The mantissa is " << function.mant << endl;
     cin.ignore(numeric_limits<streamsize>::max(), 'E' && 'e');
     cin >> function.exp;
     cout << function.exp;
}
 
 int main ()
 {
 component function;

     readCharacters(function);
     return 0;
 }

This program is getting error

27 no matching function for call to `getline(std::istream&, std::string&, bool)'
It was compiling fine before, I don't know what I did :(. It's tiny code, I know.

Share this post


Link to post
Share on other sites
Advertisement
The error message seems very informative. `std::getline' takes two arguments: a reference to a `std::istream' and a reference to a `std::string'. What do you want to happen with the third argument of type `bool'?

Share this post


Link to post
Share on other sites

Unrelated to the error message, but shouldn't the datatypes of the members of component be reversed (number with fractional part for the mantissa, and integer exponent)?

Share this post


Link to post
Share on other sites

The error message seems very informative. `std::getline' takes two arguments: a reference to a `std::istream' and a reference to a `std::string'. What do you want to happen with the third argument of type `bool'?


Oh, I see what you are doing. You are trying to use the version of `std::getline' that takes a third argument of type `char', but you are passing `'E' && 'e'' instead. The operator `&&' takes two things of type bool and "ands" them together. Both 'E' and 'e' are interpreted as `true', and therefore the whole expression is just `true'. If you want to stop reading on either 'E' or 'e', the stopping feature of std::getline won't help you there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!