473,408 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

how to solve this 2 errors ?

#include <iostream.h>
#include <string>
using namespace std;
void output_data(struct database*data_ptr);
void input_data(struct database*data_ptr);
struct database {
int id_number;
int age;
float salary;
string name;
};
int main()
{
struct database employee;
struct database* sp;
sp = &employee;
input_data(sp);
output_data(sp);
return 0 ;
}
void output_data(struct database*data_ptr)
{
cout << "*********************************\n";
cout << "name = " << data_ptr->name << "\n";
cout << "id_num = " << data_ptr->id_number << "\n";
cout << "age = " << data_ptr->age << "\n";
cout << "salary = " << data_ptr->salary << "\n";
cout << "*********************************\n";
}
void input_data(struct database*data_ptr)
{
int i_tmp;
float f_tmp;
string s_tmp;
cout<<"enter name:";
cin >>s_tmp;data_ptr->name = s_tmp;
cout << "enter id_number :";
cin >> i_tmp;data_ptr->id_number = i_tmp;
cout << "enter age :";
cin >> i_tmp;data_ptr->age = i_tmp;
cout << "enter salary:";
cin >> f_tmp;data_ptr->salary = f_tmp;;
cout<<endl;
}






The 2 errors are :
C:\Users\Omar\Desktop\Cpp1.cpp(24) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable convers
ion)
C:\Users\Omar\Desktop\Cpp1.cpp(36) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable convers
Oct 31 '08 #1
4 1519
boxfish
469 Expert 256MB
You are using the deprecated header iostream.h. Try changing it to
#include <iostream>
I think that will make your program work.
Hope this helps.
By the way, when you post code, please surround it with code tags. Put [CODE] before it and [/CODE] after it so it shows up in a code box with a monospace font and the indentation isn't wrecked. Thanks.
Oct 31 '08 #2
boxfish thnx alot for ur help and ill take it into consideration next time :)
Oct 31 '08 #3
AmeL
15
Please look at this
Expand|Select|Wrap|Line Numbers
  1. ...........................................................
  2. void input_data(struct database*data_ptr)
  3. {
  4. int i_tmp;
  5. float f_tmp;
  6. string s_tmp;
  7. cout<<"enter name:";
  8. cin >>s_tmp;data_ptr->name = s_tmp;
  9. cout << "enter id_number :";
  10. cin >> i_tmp;data_ptr->id_number = i_tmp;
  11. cout << "enter age :";
  12. cin >> i_tmp;data_ptr->age = i_tmp;
  13. cout << "enter salary:";
  14. cin >> f_tmp;data_ptr->salary = f_tmp;;
  15. cout<<endl;
  16. }
  17.  
Well, the first error as the above forumer stated; change your iostream.h to iostream.
but the compiler produced two different errors.
Expand|Select|Wrap|Line Numbers
  1. //cout<<"enter name:";       <=== this is wrong
  2. cout << "enter name:";     // <=== this is right
  3. ...................
  4. //cout<<endl; <=== this is wrong
  5. cout << endl;       // this is right
  6.  
So the problem is you left no space between cout and <<

Thanks
/AmeL
Nov 1 '08 #4
archonmagnus
113 100+
....
So the problem is you left no space between cout and <<
...
The whitespace in a C++ code is (mostly) irrelevant and (mostly) serves to make the code more readily parsed by humans rather than the compiler. For instance, GCC readily compiles the following (admittedly mangled) code:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (int argc, char *argv[])
  6. {
  7.     unsigned
  8.     short
  9.     xyzzy
  10.      = 0;
  11.  
  12.     cout
  13.         <<
  14.  "Line 1..."
  15.  
  16. <<
  17.  
  18.         endl<<
  19.  
  20.     "Line 2..."             <<
  21. endl
  22.                  <<"Line 3..."<<endl
  23. <<"Input Integer value: ";
  24.  
  25. cin
  26.               >>
  27.                           xyzzy;
  28.  
  29. cout<<"    Input: " << xyzzy << endl;
  30.  
  31.     return 0;
  32. }
  33.  
Producing the (rather straightforward) output:
Expand|Select|Wrap|Line Numbers
  1. Line 1...
  2. Line 2...
  3. Line 3...
  4. Input Integer value: 4
  5.     Input: 4
  6.  
I do believe that the OP's error was simply the inclusion of an outdated library rather than minor spacing issues.
Nov 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rob R. Ainscough | last post by:
I keep getting this error message when I build my solution: Error: The dependency 'xxx.xx.xx, Version=1.0.2067.27633, Culture=neutral' in project 'xxx.xx.xx' cannot be copied to the run directory...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
4
by: Shapper | last post by:
Hello, I need to load a XML file and call a function if it wasn't possible. I have this: Sub Build_RSS() Dim news As New XmlDocument() If news.Load("http://www.domain.com/news.rss") Then...
0
by: Mamatha | last post by:
Hi I have one VB.NET application and i declare a thread as a public variable in the form.I want to declare this same thread as a public variable according to my flexibility,so i have to declare...
5
by: mickey22 | last post by:
Hi, I am getting some errors in building my project I tried to build a C++ file say abc.cpp and I have put the all the directories to include necessary library files and header files..But I...
3
by: thalinx | last post by:
Hi can ayone help me with this program, cause i dont know how to solve the compiling errors here. thanks # include<stdlib.h> # include<conio.h> # include<stdio.h> # define MAXCADENA 8 # define...
2
by: NannMaw | last post by:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Server Error in '/WebSite1' Application. -------------------------------------------------------------------------------- Invalid postback or callback argument. ...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
1
by: Oltmans | last post by:
Hi all, I've been writing C# code using Visual Studio 2005 for some time now but for the first time I've to write ANSI C code using Visual Studio 2005. I followed this article...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.