Counting Numbers of Symbols in a line

closed account (D3R4216C)
I want to count the number of characters written in each line and then display the number. Would appreciate any kind of help?

I am trying to read them into a vector..

vector <int> get_zeichen (string datei_name)

{
vector <int> zeichen_anzahl ;

ifstream quelldatei(datei_name) ;
int zeichen_d;

while( gcount( quelldatei, zeichen_anzahl) ) zeichen_d.push_back(zeichen_anzahl) ;

return zeichen_anzahl;
}

int zeichen_wizard()
{
char datei_name[25];

cout << "Insert Name of File:" << endl;

cin >> datei_name;

vector<int> zeichen_anzahl = get_zeichen(datei_name);

if(!zeichen_anzahl.empty() )
{
size_t current_line = 0 ;
cout << "n = für nächste Linie, v = für vorherige, q = Programm beenden\n\n" ;
char command ;

do
{
cout << current_line+1 << ". " << zeichen_anzahl[current_line] << '\n' ;
cin >> command ;
command = tolower(command);

cout << "\nBefehl: '" << command << "'\n" ;
switch(command)
{
case 'n' :
if( current_line < ( zeichen_anzahl.size() - 1 ) ) ++current_line ;
else cout << "Es geht nicht mehr weiter\n" ;
break ;

case 'p' :
if( current_line > 0 ) --current_line ;
else cout << "Es geht nicht mehr weiter\n" ;
break ;
}
}
while( command != 'q' ) ;
}
return 0;
}
closed account (48bpfSEw)
use a map to solve this problem!

map<char,int> m;

for (int i=0;i<countOfLine;i++)
char c = strLine[i];
m[c] ++;
}

The map contains then all the characters of the line and the count of their occurances.
Last edited on
Topic archived. No new replies allowed.