Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cin not accepting String variables in Turbo C++

Posted on 2006-11-27
4
Medium Priority
?
1,642 Views
Last Modified: 2013-11-17
[C++ Error] Unit2.cpp(12): E2094 'operator<<' not implemented in type
'ostream' for arguments of type 'string'

I'm getting this error each time i try to use 'cin' function to input String variables from the console. I'm using Turbo C++ Explorer I downloaded recently from borland.com.

How to do i get rid of this error?
0
Comment
Question by:VbMonk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Jose Parrot earned 400 total points
ID: 18042466
That's right, VbMonk, there is no << for cin.

Exemple:
int number;
cin>>number;

The opposite direction, say <<, is used for cout.
Example:
int number=10;
cout<<number<<endl;

Jose
0
 
LVL 18

Expert Comment

by:Jose Parrot
ID: 18061065
Still need a help?
Let me change the approach, as the message error is related to cout (not cin).
E2094 error reason is
"The operator you are calling is not defined in this class. When you have an expression: x + x, where x is of type class X, the operator + has to be defined in class X and be accessible."

You may want to check the following example.
Example

//
// string.cpp
//
 #include<string>
 #include <iostream>
 using namespace std;
 int main()
 {
   string test;
   //Type in a string over five characters long
   while(test.empty() || test.size() <= 5)
   {
     cout << "Type a string between 5 and 100 characters long. " << endl;
     cin >> test;
   }
   //Test operator[] access
   cout << "Changing the third character from " 
        << test[2] << " to * " << endl;
   test[2] = '*';
   cout << "now its: " << test << endl << endl;

   //Try the insertion member function
   cout << "Identifying the middle: ";
   test.insert(test.size() / 2, "(the middle is here!)");
   cout << test << endl << endl;

   //Try replacement
   cout << "I didn't like the word 'middle',so "
           "instead, I'll say:" << endl;
   test.replace(test.find("middle",0), 6, "center");
   cout << test << endl;
   return 0;
 }

Program Output

Type a string between 5 and 100 characters long.
roguewave <----- you typed this
Changing the third character from g to *
now its: ro*uewave
Identifying the middle: ro*u(the middle is here!)ewave
I didn't like the word 'middle', so instead, I'll say:
ro*u(the center is here!)ewave

Are the includes and construction in your code as in the abova example? Does this sample runs properly in your environment?

Jose
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question