problem with c++

S

Sebu¶

Hello!

I have a little problem with one thing.

Write the program, which change every second letter on the big letter, in
every word which I "cin" from keyboard.
For example:

John has a cat.

JOhn hAs a cAt.


Please help me!
========
sebussebus
 
V

Victor Bazarov

Sebu¶ said:
Hello!

I have a little problem with one thing.

Which "thing" do you have the problem with?
Write the program, which change every second letter on the big letter, in
every word which I "cin" from keyboard.
For example:

John has a cat.

JOhn hAs a cAt.


Please help me!

Help you, how? Write it for you?
 
S

Sebus

I have program:

===========
#include <string>
#include <iostream>
#include <cctype>
#include <string>

using namespace std;
int main( )
{
string s;
do
{
cin >> s;
s[2]=to_upper(s[2]);
cout << s << ' ';
}
while(cin);
cout << endl;
}
=========

But DevC++ write me:
'to_upper' undeclared (first use this function).

I can't see it where it isn't undelclared?
 
I

int2str

Always post the code if you have it right away. Saves you from getting
the replies you got.
I have program:

===========
#include <string>
#include <iostream>
#include <cctype>
#include <string>

You already included said:
using namespace std;
int main( )
{
string s;
do

while( cin >> s ) ...
{
cin >> s;
s[2]=to_upper(s[2]);

to_upper() doesn't exist. It's toupper().
Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...
cout << s << ' ';
}
while(cin);
cout << endl;
}
=========

But DevC++ write me:
'to_upper' undeclared (first use this function).

I can't see it where it isn't undelclared?

Cheers,
Andre
 
R

red floyd

Sebus said:
I have program:

===========
#include <string>
#include <iostream>
#include <cctype>
#include <string>

using namespace std;
int main( )
{
string s;
do
{
cin >> s;
s[2]=to_upper(s[2]);
cout << s << ' ';
}
while(cin);
cout << endl;
}
=========

But DevC++ write me:
'to_upper' undeclared (first use this function).

I can't see it where it isn't undelclared?

toupper(), not to_upper().
 
M

Markus Moll

Hi

Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...

Surely you meant three.

Markus
 
S

Sebus

Not three, but one it's ok.
The every second letter have to toupper. :)

I have one more thing:
==

write program, which rename name of files (all files) in catalogue "test",
to add "0" to the name of file.
For example:

we have three files:
d://test//file1.dat
d://test//file2.dat
d://test//file3.dat

and we have to have:

d://test//file10.dat
d://test//file10.dat
d://test//file10.dat


I used "rename" but i don't know what about mask, for example:
rename(*.*,*0.*).

Could You help me???
 
I

int2str

Markus said:
Hi

Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...

Surely you meant three.

Markus

Never said I could count! :p

But yes, this also points out another mistake by the OP - s[2] is the
THIRD letter, not the second one. I based my reply on the desire to
modify the second letter.

Cheers,
Andre
 
P

peter koch

Markus Moll skrev:
Hi

Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...

Surely you meant three.

Why is that so? If s only has one character, accessing the second
character as above is surely undefined behaviour. While many (all?)
std::string implementations always have room for the null-character (in
case the user calls c_str()), this is not required.

/Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top