How to read in a txt file and Change Uppercase toLowercase

I have to read multiple text files and change all uppercase to lowercase. i also put in a little extra with finding values and spaces and punctuation. But nothing comes out so i don't know if the file is even being read or maybe I'm reading it but not accessing the right way.


string stdins;
char data;
//string line;
vector<char> a;
ifstream read;

read.open("ds.txt");
while( getline(cin,stdins) ) {

read >> data;
if(isupper(data))
tolower(data);

if((data=='a') ||(data=='e') ||(data=='i') ||(data=='o') || (data=='u'))
vow++;

if(data != ' ')
other++;

if(data==' ')
space++;

cout << data;
}

read.close();

cout << stdins;
You can use is_open() to verify that the file opened successfully.

http://www.cplusplus.com/reference/fstream/ifstream/is_open/
Fix:
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
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <cctype>
using namespace std;
string stdins;
char data;
double vow=0, other=0, space=0;
//string line;
vector<char> a;

int main()
{ifstream read;
read.open("ds.txt");
if(!read.is_open())
{cerr<<"There was a problem opening the file."<<endl;
return 10;}
while(read>>data){
if(isupper(data))
tolower(data);
if((data=='a')||(data=='e')||(data=='i')||(data=='o')||(data=='u'))
vow++;
if(data!=' ')
other++;
if(data==' ')
space++;
cout << data;
}
read.close();
cout<<stdins;
return 0;
}
Last edited on
Topic archived. No new replies allowed.