i make a program to multiply 2 binarry numbers

#include <iostream>
#include<string>
 using namespace std;
 void main()
 {
     string y,a;
     string S1="00000";
     cout<<"plz ener two numbers"<<endl;
     cin>>y;
     cin>>a;
     cout << "Sting S1\t\t" << S1 << endl;
     cout << "S1.size\t\t\t" << S1.size() << endl;
     int n=a.length();
         n=a[4];
         if(n[4]==0)
         {
           string S2=a;
           S2=S1+S2;
             S2>>=1;
             S1= S2.substr ( 0,4);
             a= S2.substr ( 5,9);
         }
         else
         {
             S1+=y;
             string S2=a;
             S2=S1+S2;
             S2>>=1;
             S1= S2.substr ( 0,4);
             a= S2.substr ( 5,9);
         }
 }

but the following errors appear to me

1>------ Build started: Project: 111, Configuration: Debug Win32 ------
1>Compiling...
1>111.cpp
1>c:\documents and settings\ahmed hassan\my documents\visual studio 2008\projects\111\111\111.cpp(15) : error C2109: subscript requires array or pointer type
1>c:\documents and settings\ahmed hassan\my documents\visual studio 2008\projects\111\111\111.cpp(19) : error C2676: binary '>>=' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\documents and settings\ahmed hassan\my documents\visual studio 2008\projects\111\111\111.cpp(28) : error C2676: binary '>>=' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>Build log was saved at "file://c:\Documents and Settings\Ahmed Hassan\My Documents\Visual Studio 2008\Projects\111\111\Debug\BuildLog.htm"
1>111 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Main() returns an int. Give this a read.

You cannot use the bitshift operator with a string, the compiler states that very clearly. You could probably write your own shift function that will push a 0 onto the beginning or the end of your string. Otherwise for the built-in ones to work you'd need to convert your binary string to an unsigned int and work with the bits using masks.

i solve the first problem now the code is

#include <iostream>
#include<string>
 using namespace std;
 void main()
 {
	 string y,a;
	 string S1="00000";
	 cout<<"plz ener two numbers"<<endl;
	 cin>>y;
	 cin>>a;
     cout << "Sting S1\t\t" << S1 << endl;
     cout << "S1.size\t\t\t" << S1.size() << endl;
	 int n=a.length() ;
		 n=a[4];
		 if(a[4]==0)
		 {
           string S2=a;
		   S2=S1+S2;
			 S2>>=1;
             S1= S2.substr ( 0,4);
             a= S2.substr ( 5,9);
		 }
		 else
		 {
			 S1+=y;
             string S2=a;
		     S2=S1+S2;
			 S2>>=1;
             S1= S2.substr ( 0,4);
             a= S2.substr ( 5,9);
		 }
 }

the following errors appear:

1>------ Build started: Project: 111, Configuration: Debug Win32 ------
1>Compiling...
1>111.cpp
1>c:\documents and settings\ahmed hassan\my documents\visual studio 2008\projects\111\111\111.cpp(19) : error C2676: binary '>>=' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\documents and settings\ahmed hassan\my documents\visual studio 2008\projects\111\111\111.cpp(28) : error C2676: binary '>>=' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>Build log was saved at "file://c:\Documents and Settings\Ahmed Hassan\My Documents\Visual Studio 2008\Projects\111\111\Debug\BuildLog.htm"
1>111 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

You cannot use the bitshift operator with a string

That's pretty much still the problem with the code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.