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?
#include <iostream>
#include <istream>
#include <string>
usingnamespace 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;
}
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