2017-09-20 3 views
-5

Dieser C++ Code gibt mir Fehler und ich weiß nicht, wie Sie diese Fehler entfernen.
Code:Wie kann ich diesen C++ Code arbeiten lassen?

#include <iostream> 
#include <string> 
#include <fstream> 
#include <cctype> 
#include <iomanip> 
using namespace std; 
string& RaiseItToUpperCase(string& w) 
{ 
int len = w.length(); 
for (int index =0; index <len; index++) 
    w[index]= toupper(w[index]); 
return w; 
} 
void LoadData() 
{ 
string filename; 
while(true) 
{ 

    cout<<"Enter Data file:"; 
    cin>>filename; 
    cout<<"Filename entered"<<filename<<endl; 
    ifstream myfile(filename.c_str()); 
    if(!myfile.good()) 
    { 

     cout<<"Please Enter a Valid text File"<<endl; 
     continue; 
    } 
    static std::string const targetExtension ("txt"); 
    if (!(filename.size() >= targetExtension.size() 
    && std::equal (filename.end() - targetExtension.size(), 
    filename.end(), 
    targetExtension.begin()))) 
    { 
     cout<<"File is not txt"<<endl; 
     continue; 
    } 
    break; 
} 
string i = filename; 
string o; 
cout<<"Enter an output file name:"<< endl; 
cin>>o; 
ofstream output; 
ifstream input(filename); 
output.open(o.c_str()); 
int charc =0; 
int numw =0; 
int longl =0; 
int shortl =10000; 
while (input>>1) 
{ 
    numw++; 
    charc = charc + i.length() +1; 
    if (i.length() > longl) 
    { 
     longl = i.length(); 
    } 
    if (i.length() < shortl) 
    { 
     i =RaiseItToUpperCase(i); 
     output << i; 
     if(input.get() ==32) 
     { 
      output<<" "; 
     } 
     else 
     { 
      output<<"\n"; 
     } 
    } 
    charc = charc - 1; 
    output<<"\nWord Counter Summary\n"<<endl; 
    output<<"Total Number of Words:"<<numw<<endl; 
    output<<"Total Number of Characters:"<<charc<<endl; 
    output<<" Largest Word Size:"<<longl<<endl; 
    output<<" Smallest Word Size"<<shortl<<endl; 
} 
} 
int main() 
{ 
LoadData(); 
return 0; 
} 

Dies ist C++ Programmdatei-Stream und ich versuche, diesen Code zu laufen, aber es mir eine Fehlermeldung, und ich bin, um herauszufinden, nicht in der Lage, wie diese Fehler entfernen
so Kann jemand sagen Sie mir, wie diese Fehler zu entfernen und diesen Code ausführen machen

aktualisieren

hier der Fehler:

Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion) c:\users\acer\documents\visual studio 2012\projects\consoleapplication15\consoleapplication15\sour‌​ce.cpp 52 1 ConsoleA‌​pplication15

Und Dank im Voraus

+3

Welchen Fehler gibt es? – Subaz

+0

Fehler Fehler C2679: binäre '>>': kein Operator gefunden, der einen rechten Operanden vom Typ 'int' verwendet (oder es gibt keine akzeptable Konvertierung) \t c: \ users \ acer \ documents \ visual studio 2012 \ consoleapplication15 \ consoleapplication15 \ source.cpp ConsoleApplication15 –

+0

und andere Fehler zu –

Antwort

0

Was tun Sie in while (input>>1) tun wollen? Wenn Sie etwas auslesen:

  • Wenn Sie int8_t auf eine ganze Zahl lesen möchten (oder int16_t/int32_t etc.): int8_t number = 0; while (input >> number)
  • Wenn Sie zu einem char lesen möchten: char ch; while (input >> ch)
Verwandte Themen