Read a persons name,Afunction shud write the name vertically ,on chracter per line ,place the output in the middle of the screen and clear the screen before printing.
do i have to use loop in this .. (for ,while)
i have started but donno how to complete
anyone , how to do this …
thnx
Sorry globe, usually people get slow response in this forum, plz don't mind that .... i'm not in direct touch with C++ since long time. But ....
One way you can do it by using a sub-string function (i guess it's "substr()") to pick each character from your string/name and locate it where you want to print. And offcourse this way would require the loop (as you mentioned). I think both 'for' and 'while' loops would work.
yea,i will try to that,
anyways,thnx for reply both of you
next time i am not goin to post thread like this askin for code straight away....
cu guys :)
globe, you can ask for code but be patient until a coder reads your question.
You can access individaul characters within a string in several ways. One of them is at() member function of string class another is using overloaded ] operator since a string literal itself is an array. So you can use index to obtain each character. However, the ] operator doesnt warn you if you attempt to access a character thats out of bounds (beyond the end of the string, for example). The ] opeartor behaves this way with real arrays, and it's more efficient. However, it can lead to hard-to-diagnose program bugs.
It's safer to use the at() function, which causes the program to stop if you use an out-of-bounds index (it actually throws an exception).
Look at this example:
// stringch.cpp
// accessing characters in string objects
#include <iostream>
#include <conio>
#include <string>
using namespace std;
int main()
{
string word = "paklinks.com/gs";
int wlen = word.length(); // length of the string object
clrscr(); // clear screen
for(int k=0; k<wlen; k++)
cout << word.at(k) << endl; // exception if out of bounds
// cout << word[k] << endl; // no warning if out-of-bounds
return 0;
}
Printing in the middle of screen is your home-work. You may need to study the console graphics functions e.g. set_cursor_pos() clear_screen() wait(n) clear_line() etc.
=)
You can access individaul characters within a string in several ways. One of them is at() member function of string class another is using overloaded ] operator since a string literal itself is an array. So you can use index to obtain each character. However, the ] operator doesnt warn you if you attempt to access a character thats out of bounds (beyond the end of the string, for example). The ] opeartor behaves this way with real arrays, and it's more efficient. However, it can lead to hard-to-diagnose program bugs.
An overloaded operator pseudo-code would be:
string str = "Rana Ihtesham Ali";
for(int k=0; k
It's safer to use the at() function, which causes the program to stop if you use an out-of-bounds index (it actually throws an exception).
Look at this example:
```php
// stringch.cpp
// accessing characters in string objects
#include
#include
#include
using namespace std;
int main()
{
string word = "paklinks.com/gs";
int wlen = word.length(); // length of the string object
clrscr(); // clear screen
for(int k=0; k
Printing in the middle of screen is your home-work. You may need to study the console graphics functions e.g. set_cursor_pos() clear_screen() wait(n) clear_line() etc.
=)
ok ,do i need to use cin or cin.getline();