string conversion

Page 1 of 1

2 Replies - 5774 Views - Last Post: 02 April 2007 - 05:50 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=25878&amp;s=27598097435a163574391c1717f4994f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 ZORO

Reputation: 0
• Posts: 6
• Joined: 01-April 07

string conversion

Posted 02 April 2007 - 12:00 AM

how to convert a string variable into capital in c++ code
Is This A Good Question/Topic? 0

Replies To: string conversion

#2 v0id

Reputation: 2
• Posts: 4
• Joined: 22-November 06

Re: string conversion

Posted 02 April 2007 - 12:15 AM

Hi ZORO,

I don't know if there's such function, but you can make one by yourself, very quickly. I've just maked an example;
```#include <iostream>
#include <string>

void makeCapital(std::string &str)
{
for(int x = 0; x <= str.size()-1; x++)
if((str.at(x) >= 'a') && (str.at(x) <= 'z'))
str.at(x) -= 32;
}

int main()
{
std::string myStr = "Hello, World!";

makeCapital(myStr);
std::cout << myStr << std::endl;

return 0;
}

```

The only thing to actually know, is the algorithm (if I can say so).
Each small letter have to be subtracted by a ' ', or 32 (ASCII). That's because there's 32 from the big letter, for example 'A', to it's smaller letter, 'a'.

• g+ + -o drink whiskey.cpp

Reputation: 250
• Posts: 13,507
• Joined: 12-July 02

Re: string conversion

Posted 02 April 2007 - 05:50 AM

http://www.dreaminco...e/snippet39.htm

or using the STL

```std::transform (s.begin(),s.end(), s.begin(), toupper);

```