10 Replies - 1424 Views - Last Post: 23 July 2011 - 10:09 PM Rate Topic: -----

#1 Oryon89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-May 11

no match for operator >>

Posted 23 July 2011 - 05:00 PM

I have to create a program that allows the user to input two different equations and the program will determine if the lines intersect and if they do then the program will output the point of intersection. I'm not having a problem with the assignment in general the problem I am having is when i try to compile the program I'm getting an error that says no match found for operator >> in reference to being used in conjunction with cin. Posted below is the code and the error messages being given.


#include <cstdlib>
#include <iostream>

using namespace std;

string equation1[1];
string equation2[1];

int main(int argc, char *argv[])
{
    cout << "This program will tell the user if two lines intersect and at what point.\n" << endl;
    cout << "Please input the first equation: ";
    cin >> equation1[1] >> endl;
    cout << "Please input the second equation: ";
    cin >> equation2[1] >> endl;
     
    system("PAUSE");
    return EXIT_SUCCESS;
}




Here is the error message I am receiving.

Line 13 no match for 'operator>>' in 'std::operator>> [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)(&std::cin)), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(((std::string*)(&equation1)) + 4u))) >> std::endl'

Is This A Good Question/Topic? 0
  • +

Replies To: no match for operator >>

#2 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: no match for operator >>

Posted 23 July 2011 - 05:09 PM

That is because you don't use endl with cin. Cin strictly gets user input and puts it into a string, whereas endl outputs an end of line character
Hope This Helps :)
Was This Post Helpful? 0
  • +
  • -

#3 Oryon89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-May 11

Re: no match for operator >>

Posted 23 July 2011 - 05:46 PM

View Postsk1v3r, on 23 July 2011 - 05:09 PM, said:

That is because you don't use endl with cin. Cin strictly gets user input and puts it into a string, whereas endl outputs an end of line character
Hope This Helps :)


Thanks for the help, that worked perfectly. I've made programs before and I didn't use endl with cin so I'm not sure why I used it in this one. Again, thanks for the help I really appreciate it.
Was This Post Helpful? 0
  • +
  • -

#4 Oryon89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-May 11

Re: no match for operator >>

Posted 23 July 2011 - 06:16 PM

I'm having another problem now. Im trying to use an if else statement to determine if the slopes are different but regardless of what numbers I enter the program always says they are different.

#include <cstdlib>
#include <iostream>

using namespace std;

double slope1[1];
double slope2[1];

int main(int argc, char *argv[])
{
    //Function to allow user to input the equations.
    cout << "This program will tell the user if two lines intersect and at what point.\n" << endl;
    cout << "Please input the slope of the first equation as a decimal number: ";
    cin >> slope1[1];
    cout << "Please input the slope of the second equation as a decimal number: ";
    cin >> slope2[1];
    
    //Function to determine if the two slopes are the same.
    if(slope1 != slope2)
    {
         cout << "These lines intersect." << endl;
    }
    else 
    {
         cout << "These lines do not intersect please enter two new slopes." << endl;
         cin >> slope1[1];
         cin >> slope2[1];
    }
    
     
     
    system("PAUSE");
    return EXIT_SUCCESS;
}


Was This Post Helpful? 0
  • +
  • -

#5 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: no match for operator >>

Posted 23 July 2011 - 06:23 PM

What are you trying to do with slope1[1] and slope2[1]? These are both arrays which have one element, which is pointless, because you could just use a normal value. In fact I believe that that is what you were trying to do. Later on you also input into these vales as if they were arrays but you go out of bounds.
Take the [1] bit off of both values and read this and this
Hope This Helps :)
Was This Post Helpful? 1
  • +
  • -

#6 Hiram  Icon User is offline

  • D.I.C Head

Reputation: 69
  • View blog
  • Posts: 203
  • Joined: 02-June 09

Re: no match for operator >>

Posted 23 July 2011 - 07:58 PM

What sk1v3r has pointed out is exactly the issue. When you get to line 19, you're comparing arrays then, which means you're comparing memory addresses.
Was This Post Helpful? 0
  • +
  • -

#7 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3116
  • View blog
  • Posts: 19,153
  • Joined: 14-September 07

Re: no match for operator >>

Posted 23 July 2011 - 08:00 PM

An array of size one's only valid index is zero.
Was This Post Helpful? 0
  • +
  • -

#8 Oryon89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-May 11

Re: no match for operator >>

Posted 23 July 2011 - 09:23 PM

Ok i believe i fixed all the previous problems but now I can't think of a way to solve the equations within the program. Ive done some research and the best information i could find says to download the GSL-GNU scientific library. I'm not even sure how to use that with dev-c++. Any help would be greatly appreciated. Below is the code I have written so far.

#include <cstdlib>
#include <iostream>

using namespace std;

double m1;
double m2;
double y1;
double y2;
double b1;
double b2;

int main(int argc, char *argv[])
{
    //Function to allow user to input the equations.
    cout << "This program will tell the user if two lines intersect and at what point.\n" << endl;
    cout << "Please input the slope of the first equation as a decimal number: ";
    cin >> m1;
    cout << "Please input the slope of the second equation as a decimal number: ";
    cin >> m2;
    
    //Function to determine if the two slopes are the same.
    if(m1 != m2)
    {
         cout << "These lines intersect." << endl;
    }
    else 
    {
         cout << "These lines do not intersect please enter two new slopes." << endl;
         cin >> m1;
         cin >> m2;
         
    }
    
    //Function to allow user to input the equation
    cout << "For this program you must enter the equation in the form y=mx+b.\n" << endl;
    cout << "Please input the value of y in the first equation: ";
    cin >> y1;
    cout << "Please input the value of y in the second equation: ";
    cin >> y2;
    cout << "Please input the value of b in the first equation: ";
    cin >> b1;
    cout << "Please input the value of b in the second equation: ";
    cin >> b2;
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
} 


Was This Post Helpful? 0
  • +
  • -

#9 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: no match for operator >>

Posted 23 July 2011 - 09:31 PM

> Ok i believe i fixed all the previous problems but now I can't think of a way to solve the equations within the program

Well, work it on further. You can develop an algorithm to solve this. How would you do it by hand, eh?

> Ive done some research and the best information i could find says to download the GSL-GNU scientific library

Yo uare going to use GSL? Talk about overkill. Actually, you might just fail your assignment on that. If it passes compile, whoever looks it at probably won't be too happy.

You'll have to follow instructions in the GSL folder. Unpack the sources and read the documentation. It tells you how to build the library. But again, this is ridiculous.
Was This Post Helpful? 0
  • +
  • -

#10 Oryon89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-May 11

Re: no match for operator >>

Posted 23 July 2011 - 09:44 PM

View PostOler1s, on 23 July 2011 - 09:31 PM, said:

> Ok i believe i fixed all the previous problems but now I can't think of a way to solve the equations within the program

Well, work it on further. You can develop an algorithm to solve this. How would you do it by hand, eh?

> Ive done some research and the best information i could find says to download the GSL-GNU scientific library

Yo uare going to use GSL? Talk about overkill. Actually, you might just fail your assignment on that. If it passes compile, whoever looks it at probably won't be too happy.

You'll have to follow instructions in the GSL folder. Unpack the sources and read the documentation. It tells you how to build the library. But again, this is ridiculous.


No i wasn't saying i was going to use it. I said that I did research on how to solve linear equations in C++ and that was the only information I really found on the subject. I'm very new to programming so I would need a simple approach to solving equations in C++. I was asking if someone could point me in the right direction on how to do it. I would appreciate any information that you could give me.
Was This Post Helpful? 0
  • +
  • -

#11 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: no match for operator >>

Posted 23 July 2011 - 10:09 PM

> I said that I did research on how to solve linear equations in C++

Which will get you solutions like GSL. That's not what you want. You need to sit down with pen and paper and figure out a series of steps to arrive at a solution. Then you need to represent those steps in code.

If you have no pen and paper solution, there's no point in talking about code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1