-2

I am trying to get a sequence of words from cin and store the values in a vector. After I’ve read all the words, I want to process the vector and change each word to uppercase.

This is my code:

#include<iostream>
#include<string>
#include<cctype>
#include<vector>

using namespace std;

int main() {
    string line;
    vector<string> words;
    while( getline(cin, line) ) {
        words.push_back(line);
    }
    for (auto &c : words) {
        c = toupper(c);
        cout << c << endl;
    }
}

I am getting error at the c = toupper(c):

||=== Build: Debug in test (compiler: Cygwin GNU GCC Compiler) ===|
C:\Users\Ajay\Desktop\test\test\main.cpp||In function ‘int main()’:|
C:\Users\Ajay\Desktop\test\test\main.cpp|15|error: no matching function for call to ‘toupper(std::basic_string<char>&)’|
C:\Users\Ajay\Desktop\test\test\main.cpp|15|note: candidates are:|
\usr\include\ctype.h|20|note: int toupper(int)|
\usr\include\ctype.h|20|note:   no known conversion for argument 1 from ‘std::basic_string<char>’ to ‘int’|
\usr\lib\gcc\i686-pc-cygwin\4.8.2\include\c++\bits\locale_facets.h|2596|note: template<class _CharT> _CharT std::toupper(_CharT, const std::locale&)|
\usr\lib\gcc\i686-pc-cygwin\4.8.2\include\c++\bits\locale_facets.h|2596|note:   template argument deduction/substitution failed:|
C:\Users\Ajay\Desktop\test\test\main.cpp|15|note:   candidate expects 2 arguments, 1 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
cigien
  • 57,834
  • 11
  • 73
  • 112
ajknzhol
  • 6,322
  • 13
  • 45
  • 72

1 Answers1

2
    for(auto &word : words){
        for (auto &c : word) {
            c = ::toupper(c);
            cout << c << endl;
        }
    }
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70