What is wrong with my code?

I am writing a program in which you type a word and a segment of letters from that word. When you do this, the program tells you how many letters there are, and finds the segment in the word. I am using the code that our teacher showed us but I changed it so that the users could input the word.

#include <iostream>
#include <istream>
using namespace std;
int main ()
{
string word,segment;
cout << "Type in a word and a segment (leave a space between them): " << endl;
cin >> word,segment;
cout << word.length() << endl;
cout << word.find(segment) << endl;

I am getting a 'no operator ">>" matches these operands' error. What is wrong?
I think cin>>word,segment is not a valid command
Try cin>>word>>segment;
And instead of asking the user to leave a space request them to hit enter

I don't know if I'm right though :)
You forgot to #include <string>

corrected code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <istream>
#include <string>
using namespace std;
int main ()
{
	string word, segment;
	cout << "Type in a word and a segment (leave a space between them): " << endl;
	cin >> word >> segment;
	cout << word.length() << endl;
	cout << segment.length() << endl;
	
	system("Pause"); //Pauses the program
	return 0;
}
Last edited on
I tried both solutions and neither of them worked. I am still getting the same error: 'no operator ">>" matches these operands'
I tested the program before posting here...are you using vb??
closed account (Dy7SLyTq)
a) why are you using istream? you dont need it.
b) what are you using for input

@jot: i think you mean vs, because vb is a programming language. and that wouldnt matter. it would be the compiler, visual c++, which once again wouldnt matter in a program like this
Can you post the full error verbatim? And your code?
agghh:,, that system(), have you #include <cstdlib> ?

I have no idea why you have that no operator bla bla error...
Topic archived. No new replies allowed.