Converting a String into chars
Feb 11, 2017 at 6:00pm UTC
Im trying to read a string from a file "Test.txt" and then count all of the vocals
and output the number of vocals.But I get a string from the file and it gives an error when i try to read it as an array of chars.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
int x = 0;
fstream datei("C:\\Users\\Name\\Desktop\\Test.txt" , ios::in);
char zeile[200];
for (int i=0;i<201;i++){
getline(datei,zeile)
if (zeile=="a" ||zeile=="e" ||zeile=="i" ||zeile=="o" ||zeile=="u" ){
x++;
}
}
datei.close();
cout << x;
return 0;
}
This part gives me an error:
1 2 3 4 5 6 7 8
for (int i=0;i<201;i++){
getline(datei,zeile) <-- This part
if (zeile=="a" ||zeile=="e" ||zeile=="i" ||zeile=="o" ||zeile=="u" ){
x++;
}
}
Feb 11, 2017 at 6:08pm UTC
Topic archived. No new replies allowed.