Ok so sicher, im im etwas zu tun dumm: Deinfache C++ Funktionen
Ich habe eine Funktion:
int wordFunc(string a){
std::ifstream inp;
inp.open(a, std::ios::in);
if (inp.is_open()){
std::string word;
unsigned long wordCount = 0;
while(!inp.eof()){
inp >> word;
while(word.length() > 0){
wordCount++;
}
inp.close();
}
return wordCount;
}
}
den String ist eine Benutzereingabe datei.txt - seine Menge C zu sein: \ Dump \ user.txt jetzt
, wenn ich den Code aufrufen mit:
int main(){
string file;
int words = 0;
file = "C:\\Dump\\user.txt";
int a = wordFunc(file, words);
cout << "Words: " << a << endl;
return 0;
}
die Konsole hält nur - ich havnt i codiert alles n C++ in vielen Jahren, also ich bin definitiv rostig - jede Hilfe?
EDIT Mit Hilfe einer Art sould endete Ich mag dieses
unsigned long wordFunc(const std::string& a){
std::ifstream inp(a);
system("cls");
unsigned long wordCount = 0;
std::string word;
while(inp >> word)
{
wordCount++;
}
return wordCount;
}
Für die Funktion steigen -
Update sollte geschrieben
Sind Sie sicher, dass Sie die richtige Schnittstelle haben? Im Hauptprogramm rufen Sie wordFunc mit zwei Argumenten (Datei und Wort) auf, und die Funktion hat nur ein Argument (a). – Glenn
Ja - ich habe das auch gefangen - es war definitiv die While-Schleife –
Ist das Hausaufgaben? – Johnsyweb