Error in program please help..!!

I am trying this program for eliminating the vowels from a text.

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
34
35
36
37
38
39
#include <iostream>
#include <vector>
#include <ctype.h>

bool isVowel(char c, int indx)
{
  c = tolower(c);
  if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
    return true;

  // Don't flag a leading "y" as a vowel, ie "yellow"
  if ((c == 'y') && (indx != 0))
    return true;
  return false;
}

int
main(int argc, char* argv[])
{
  std::string word;
  std::vector<std::string> container;

  while(std::cin >> word) {

    if (word.size() > 3) {
      std::string newword;
      for (int i=0; i<word.size(); i++) {
        if (!isVowel(word[i], i))
          newword.push_back(word[i]);
      }

	
      std::cout << newword << " ";
    }
    else
      std::cout << word << " ";
  }
  std::cout << "\n";
  return 0;


here is an error while debugging that while trying to match the argument list '(std::istream, std::string).

Can someone please correct me in the program?
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
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <ctype.h>

bool isVowel(char c, int indx)
{
  c = tolower(c);
  if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
    return true;

  // Don't flag a leading "y" as a vowel, ie "yellow"
  if ((c == 'y') && (indx != 0))
    return true;
  return false;
}

int
main(int argc, char* argv[])
{
  std::string word;
  std::vector<std::string> container;

  while(std::cin >> word) {

    if (word.size() > 3) {
      std::string newword;
      for (int i=0; i<word.size(); i++) {
        if (!isVowel(word[i], i))
          newword.push_back(word[i]);
      }


      std::cout << newword << " ";
    }
    else
      std::cout << word << " ";
  std::cout << "\n";
  return 0;

  }
}
this is the same program i posted, i am getting errors and not not able to run.
can someone tell me what is wrong in the program?
Add #include <string>

Also, in your first post, you need to close the curly bracket of the main function.

Good luck!
Last edited on
@croco- thanks now there are no errors.
but i have a problem with the output. when i enter a line it just returns the letters of the first word not the complete line?
And is it possible to make a text file and safe text there and call that one instead of typing as input?
Last edited on
This is reading from a file.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
#include <fstream>
#include <string>


bool isVowel(char c, int indx)
{
  c = tolower(c);
  if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
    return true;

  // Don't flag a leading "y" as a vowel, ie "yellow"
  if ((c == 'y') && (indx != 0))
    return true;
  return false;
}

int main(int argc, char* argv[])
{
  std::string word;
  std::vector<std::string> container;
  std::ifstream myfile;

  myfile.open ("C:\\Users\\CroCo\\Desktop\\data.txt");  // Add the full path of the file
  
  // Check first before go further
  if (myfile.fail())
  {
	  std::cerr << "The file could not be opened. " << std::endl;
  }

  while( !myfile.eof() )   // Read data from the file until hit the end of the file
  {

    std::getline(myfile, word); // reading line by line
	
    if (word.size() > 3) 
	{
      std::string newword;
      for (int i=0; i<word.size(); i++)
	  {
        if (!isVowel(word[i], i))
          newword.push_back(word[i]);
      }

	
      std::cout << newword << " ";
    }
    else
      std::cout << word << " ";
  }

  myfile.close(); // Close the file 
  std::cout << "\n";
  std::cin.get();
  return 0;
}
Last edited on
@akku03,
but i have a problem with the output. when i enter a line it just returns the letters of the first word not the complete line?


Yes, becuase you're putting return 0 inside the while() loop.
This is the correct code


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
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <vector>
#include <string>

bool isVowel(char c, int indx)
{
  c = tolower(c);
  if ((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
    return true;

  // Don't flag a leading "y" as a vowel, ie "yellow"
  if ((c == 'y') && (indx != 0))
    return true;
  return false;
}

int
main(int argc, char* argv[])
{
  std::string word;
  std::vector<std::string> container;

  while(std::cin >> word) {

    if (word.size() > 3) {
      std::string newword;
      for (int i=0; i<word.size(); i++) {
        if (!isVowel(word[i], i))
          newword.push_back(word[i]);
      }


      std::cout << newword << " ";
    }
    else
      std::cout << word << " ";
  std::cout << "\n";
  

  }
  return 0;
}


Good Luck!
Last edited on
@croco- thanks a lot it solved my problem.
I just have one more query is it possible to create a text file which save some words like for tomorrow to 2 mro, fine to f9 and then use these abbreviations in the program using map??
Can someone help me with that.
Last edited on
Topic archived. No new replies allowed.