掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
String型について (ID:56103)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
エラーが出るときはどんなエラーが出るのか書きましょう。 そもそもクラスの作りがとんでもないと思うのは私だけ?^^; Humanクラスの中に人数の要素がnameの配列数の形で入ってるとは。。。 自分ならこうします。 #include <iostream> #include <string> #include <stdio.h> #include <vector> class Human{ std::string name; public: Human(){}; void Input(); void Display(); }; void Human::Input(){ std::cout << "Please enter Humans' name." << std::endl; std::cin >> name; std::cout << std::endl; } void Human::Display(){ std::cout << name << std::endl; } int main(){ int num=0;//人数 std::cout << "Please enter the number of people. " << std::endl; std::cin >> num; std::cout << std::endl; std::vector<Human> people; Human t; for(int i=0;i<num;i++) { t.Input(); people.push_back(t); } for(i=0;i<num;i++) people[i].Display(); return 0; }
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.