初学者帮忙! [英] Beginner help!
问题描述
我的课上有一个问题..希望得到一些帮助
我需要创建一个打印的程序
firstName middleName lastName
然后他们的首字母
用户将输入:
John Smith Doe
输出:
John
史密斯
Doe
JSM
我可以轻松创建字符串和cout的名字,但有麻烦
找到如何打印每个字符串的第一个字母
(不能使用数组)
我是以某种方式使用忽略功能?
任何人都可以帮助我????
* aaron:< blockquote class =post_quotes>我的课上有一个问题..希望得到一些帮助
我需要创建一个程序,打印
firstName middleName lastName
然后他们的首字母
用户将输入:
John Smith Doe
输出:
John
史密斯
Doe
JSM >
我加n很容易创建字符串和cout名称,但有困难
找到如何打印每个字符串的第一个字母
(不能使用数组)
我是否以某种方式使用忽略函数?
任何人都可以帮助我????
std :: string,你应该用来表示每个名字,有一个
你可以用来提取第一个字符的成员函数的数量。
例如''at''成员函数。
- -
答:因为它弄乱了人们通常阅读文字的顺序。
问:为什么这么糟糕?
A:热门发布。
问:usenet和电子邮件中最烦人的是什么?
谢谢...
请理解这是一个简介的开头。
编程类
这个成员函数从未提及过...... 。
我包括字符串...
我现在所需要的一切s找出如何打印第一个字符
也许使用忽略功能?
#include< iostream>
#include< string>
使用命名空间std;
int main()
{
字符串优先;
字符串中间;
字符串最后;
cout<< 以First Middle Last:格式输入名称:
cin>>首先;
cin>>中间;
cin>>最后一个;
cout<<第一个<< endl<<中<< endl<<最后<< endl;
返回0;
}
aaron < AA *** @ yadavis.com>在消息中写道
news:11 ********************** @ g44g2000cwa.googlegr oups.com ...谢谢...
请理解这是编程类介绍的开始。
这个成员函数从未提及过......
我包括字符串...
现在我需要的是找出如何只打印第一个字符
也许使用忽略功能?
#include< iostream>
#include< string>
使用命名空间std;
int main()
{
字符串优先;
字符串中间;
字符串最后;
cout<< 以First Middle Last:格式输入名称:" ;;
cin>>首先;
cin>>中间;
cin>>最后;
cout<<第一个<< endl<<中<< endl<<最后<< endl;
返回0;
}
哦,如果它们是3个单独的字符串那就是'更简单。
first [0]首先是std :: string的第一个字符。
middle [0]是第一个字符std :: string middle等..
所以
std :: cout<<首先[0]<<中[0]<<最后[0]<< std :: endl;
将打印他们的姓名首字母。
它是[0]而不是[1],因为在C和C ++中,数组元素从0开始,
不是1.
I have a question in my class.. hoping to get some help
I need to create a program that will print
firstName middleName lastName
then their initials
User will input:
John Smith Doe
Output:
John
Smith
Doe
JSM
I can easily create the strings and cout the names but having trouble
finding how to print the first letter of each string
(cannot use array)
am I to use ignore function somehow?
can anyone help me????
* aaron:I have a question in my class.. hoping to get some help
I need to create a program that will print
firstName middleName lastName
then their initials
User will input:
John Smith Doe
Output:
John
Smith
Doe
JSM
I can easily create the strings and cout the names but having trouble
finding how to print the first letter of each string
(cannot use array)
am I to use ignore function somehow?
can anyone help me????
std::string, which you should be using to represent each name, has a
number of member functions you can use to extract the first character.
The ''at'' member function, for example.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
thank you...
Please understand this is the very beginning of a intro to comp
programming class
this at member function is never mention as of yet...
I am including string...
All I need now is to find out how to just print the first character
maybe the use of the ignore function?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first;
string middle;
string last;
cout << "Enter a name in the format First Middle Last: ";
cin >> first;
cin >> middle;
cin >> last;
cout << first << endl << middle << endl << last << endl;
return 0;
}
"aaron" <aa***@yadavis.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...thank you...
Please understand this is the very beginning of a intro to comp
programming class
this at member function is never mention as of yet...
I am including string...
All I need now is to find out how to just print the first character
maybe the use of the ignore function?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first;
string middle;
string last;
cout << "Enter a name in the format First Middle Last: ";
cin >> first;
cin >> middle;
cin >> last;
cout << first << endl << middle << endl << last << endl;
return 0;
}
Oh, if they are 3 seperate strings it''s even much easier.
first[0] is the first character of the std::string first.
middle[0] is the first character of the std::string middle, etc..
so
std::cout << first[0] << middle[0] << last[0] << std::endl;
would print their initials.
It is [0] instead of [1] because in C, and C++, array elements start at 0,
not 1.
这篇关于初学者帮忙!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!