Solved

cin not accepting String variables in Turbo C++

Posted on 2006-11-27
4
1,636 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 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

732 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