Solved

cin not accepting String variables in Turbo C++

Posted on 2006-11-27
4
1,632 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
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
JoseParrot 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:JoseParrot
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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…
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 columnThat will then direct you to their download page.From that page s…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

809 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