0

toupper not working

Does anybody know what the problem is with toupper? It keeps giving me an error there and I don't know why. It seems like it wants another argument but I don't think that's right. #include <fstream> #include <string> #include <algorithm> using namespace std; //declaration section class Salesperson { public: Salesperson(); void writeRecordToFile(string, int, ofstream &); void readRecordFromFile(ifstream &); string getName(); int getSales(); private: string name; int sales; }; //implementation section Salesperson::Salesperson() { name=""; sales=0; } //end of default constructor void Salesperson::writeRecordToFile(string n, int s, ofstream &outF) { transform(n.begin(), n.end(), n.begin(), toupper()); name=n; sales=s; outF<<name<<'#'<<sales<<endl; }//end of writeRecordToFile function void Salesperson::readRecordFromFile(ifstream &inF) { getline(inF, name, '#'); inF>>sales; inF.ignore(1); }//end of readRecordFromFile function string Salesperson::getName() { return name; }//end of getName function int Salesperson::getSales() { return sales; }//end of getSales function

29th May 2018, 1:34 AM
Michelle
Michelle - avatar
4 ответов
29th May 2018, 4:32 AM
Rstar
Rstar - avatar
+ 5
The toupper that you are attempting to use is actually defined in the global namespace. There is an overload of toupper() in the standard namespace, and that's what you were invoking. Clearly, it would cause a mismatch. In order to call the correct toupper, resolve the scope. std::transform(n.begin(), n.end(), n.begin(), ::toupper);
29th May 2018, 5:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Michelle Is the posted code in the thread description the full code? If it is, it appears that your main function is missing, causing the 'WinMain' reference error. Edit: Yeah, I just checked your codes. Your program is missing the main function. Just added one and it compiles without errors.
30th May 2018, 1:32 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Well std gets me fewer error messages. I added the std and reference in now it throws this: ..\Playground\-w64/mingw64..\Playground\-w64-mingw32/7.2.0/../....\Playground\-w64-mingw32..\Playground\(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status
29th May 2018, 7:22 PM
Michelle
Michelle - avatar