473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

error trying to toupper string

I am trying to upper case a string, so I have this method:

string FileSystem::toupper(string S)
{
for (int i=0; i<S.length(); ++i)
{
S[i]=toupper(S[i]);
}

return S;
}

I get the errors:
invalid conversion from `char' to `const char*'

`std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const
_CharT*, const _Alloc&) [with _CharT = char, _Traits =
std::char_traits<char>, _Alloc = std::allocator<char>]'

cannot convert `std::string' to `char' in assignment

I did some looking on the Net and it appears I have done nothing new,
in fact it is almost character by character a match of 3 samples I
found on the net.

But of course... it doesn't compile.

Nov 29 '06 #1
2 4398
<sa***@murdocks.on.cawrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
>I am trying to upper case a string, so I have this method:

string FileSystem::toupper(string S)
{
for (int i=0; i<S.length(); ++i)
{
S[i]=toupper(S[i]);
}

return S;
}

I get the errors:
invalid conversion from `char' to `const char*'

`std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const
_CharT*, const _Alloc&) [with _CharT = char, _Traits =
std::char_traits<char>, _Alloc = std::allocator<char>]'

cannot convert `std::string' to `char' in assignment

I did some looking on the Net and it appears I have done nothing new,
in fact it is almost character by character a match of 3 samples I
found on the net.

But of course... it doesn't compile.
This compiles and runs for me with the expected output of
HELLO

I'm using Micorost Visual C++ .net 2003

#include <iostream>
#include <string>

std::string toupper(std::string S)
{
for (int i=0; i < S.length(); ++i)
{
S[i]=toupper(S[i]);
}

return S;
}

int main()
{
std::string MyString("Hello");

std::cout << toupper( MyString ) << "\n";

std::string wait;
std::getline( std::cin, wait );

} // function main
Nov 29 '06 #2

Jim Langston wrote in message ...
>
This compiles and runs for me with the expected output of
HELLO

I'm using Micorost Visual C++ .net 2003

#include <iostream>
#include <string>

std::string toupper(std::string S){
for (int i=0; i < S.length(); ++i){
S[i]=toupper(S[i]);
}
return S;
}

int main(){
std::string MyString("Hello");
std::cout << toupper( MyString ) << "\n";
std::string wait;
std::getline( std::cin, wait );
} // function main
Hi Jim,
You should kick up the warning level a notch or two:

//for( int i=0; i < S.length(); ++i){
// [Warning] comparison between signed and unsigned integer expressions
// ....or is type 'int' unsigned on your machine? <G>

for( size_t i(0); i < S.size(); ++i){

// or 'std::size_t'. 'std::string::size_type' is worth a typedef (and I hate
typedef's!!<G>)

Otherwise, works fine on MinGW(GCC3.3.1).

Now, put 'toupper' (as is) in a class, and see if it still works as
advertised (call from inside the class).

class ToUpTest{ public:
void Print(std::string str, std::ostream &sos){
sos<<toupper(str)<<std::endl;
return;
} // Print(string,ostream&)
std::string toupper( std::string S ){
for( size_t i(0); i < S.size(); ++i ){
// S[ i ] = toupper( S[ i ] );
// In member function
//`std::string ToUpTest::toupper( [snip] )':
// error: invalid conversion from `char' to `const char*'
// error: initializing argument 1 of [snip]
// error: cannot convert `std::string' to `char' in assignment

S[ i ] = std::toupper( S[ i ] ); // even '::toupper()'
}
return S;
} // toupper(string)
};

{ // main() or function
std::string MyString("Hello");
// std::cout << toupper( MyString ) << "\n";

ToUpTest TuT;
TuT.Print( MyString, std::cout );
}

See the OPs problem now?
--
Bob R
POVrookie
Nov 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
5
by: Patrick Stone | last post by:
Here's a reason why javascript sucks so bad. The following *SIMPLE* piece of code will not work properly. Jesus, how I yearn for the day when a real programming language can be substituted for this...
7
by: Kerri | last post by:
Hi, I have a string 'hello world' I can UCase my string using String.ToUpper Is there anyway to just UCase the first letter ofe ach word? Thanks,
8
by: Aamir Wahid | last post by:
Hi i was trying to run a code in c++.net and i got this following error warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data i am putting my code here if any body...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
4
by: sandy | last post by:
I am trying to upper case a string, so I have this method: string FileSystem::toupper(string S) { for (int i=0; i<S.length(); ++i) { S=toupper(S); } return S;
9
by: Usman Jamil | last post by:
Hi I'm having a strange error while comparing two strings. Please check the code below. This is a simple string comparison code and works just fine on all of my machines. While debugging an...
16
by: gaga | last post by:
my function should accept a pointer to a string as its argument. and it should convert each charater to an uppercase letter. I know what i need to do, its just my syntax is all out of whack. ...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
18
by: E11esar | last post by:
Hi there. I have written an asp.net / c# web application that subscribes to a web service and all works fine. If I then enclose the page functionality of the web page within AJAX tab and accordion...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.