faz <fa*********@gmail.comwrote in message...
/* """ quote
But the array should consider 0-41(42 bits)
int main(){
char ch;
char revStr[41],correctStr[41];
int count=0
ifstream in("config.txt",ios::in | ios::binary);
if(!in){
cout << "Cannot open read file.";
return 1;
}
while(in){ // in will be false when eof is reached
in.get(ch);
if(in){
cout << ch;
correctStr[count]=ch;
count++;
}
}
correctStr[count]='\0';
fn_revrs(correctStr,revStr,count);
cout<<"\nno of characters in file :"<<count<<endl;
cout<<"correct set of characters in file :\n"<<correctStr<<endl;
cout<<"rev of characters in file :\n"<<revStr<<endl;
}
file://config.txt
001010000000000000000000110000000000000100
pls suggest me where i am wrong...
regards, fazal
""" */ quote end
Is this homework?
// --------
// .....
std::ifstream in("config.txt", std::ios_base::in|std::ios_base::binary );
if( not in ){
cout << "Cannot open read file.";
return 1;
}
while( in.get( ch ) ){
cout << ch;
correctStr[ count++ ] = ch;
}
// .....
// --------
If NOT homework:
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm// for copy, reverse
#include <iterator // for istream_iterator
// + any I missed <G>
int main(){
std::ifstream in( "config.txt" );
std::string Sdata;
std::copy( std::istream_iterator<char>( in ),
std::istream_iterator<char>(),
std::back_inserter( Sdata ) ); // put file in string
std::cout<<"\nSdata size="<<Sdata.size()<<'\n';
std::cout<<"Sdata="<<Sdata<<std::endl;
if( 8 < Sdata.size() ){
std::cout<<"\nThe 9th char is "<<Sdata.at( 8 )<<std::endl;
}
std::string RevIt( Sdata );
std::reverse( RevIt.begin(), RevIt.end() ); // reverse it
std::cout<<"RevIt="<<RevIt<<std::endl;
return 0;
} // main()
--
Bob R
POVrookie