Why you making a char... there clumsy and lack memory management and stuff... but that ain't my problem.
I look upon your code and see:
1 security hole
2 NULLs
1 wrong method
---------------------------------------------------
SYSTEM('PAUSE")
If you were in a class of mine and i saw that hideous function i would give you a big fat F. WHO EVER TAUGHT YOU SHOULD HAVE KNOWN BETTER!
system("anything")
is un-portable, slow and clumsy. let me tell you what it does.
suspend your program
1- call the operating system
2- open an operating system shell (relaunches the O/S in a sub-process)
3- the O/S must now find the PAUSE command
4- allocate the memory to execute the command
5- execute the command and wait for a keystroke
6- deallocate the memory
7- exit the OS
8- resume your program
------------------------------------
Just use
--------------------------------------
NULL
NULL = 0 right? That means:
1 2 3 4 5 6
|
int foo(NULL);
int foo (0);
//they both do the same thing!
|
Use nullptr.... if its compatible with your compiler. if its not you better not put too mich nulls in your code...... i warn you.
-------------------------------------------
ou heard of a stringstream.... its used to convert to and from strings... its the altmate tool for converting....
New 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
|
#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main()
{
string sentence;
stringstream SS;
char sentence2;
cout << "Please enter a sentence. This sentence will be converted to upper case." << endl;
getline(cin, sentence);
SS << sentence;
SS >> sentence2;
cout << sentence2;
cin.get();
return 0;
}
|
-----------------------
i also would not put Using namespace std; ans it makes the point of namespaces absoulete.
------------------------------------
you want to make it upercase... here:
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
|
#include<iostream>
#include<string>
#include <locale> //std::toupper
using namespace std;
int main()
{
string sentence;
string sentence2;
std::locale settings;
cout << "Please enter a sentence. This sentence will be converted to upper case." << endl;
getline(cin, sentence);
for(short i = 0; i < sentence.size(); ++i){
sentence2 += (std::toupper(sentence[i], settings));}
cout << sentence2;
cin.get();
return 0;
}
|