// Brandon Wall : 8/17/06
// Character Profile - Builds the characters profile using classes
#include <string>
#include <iostream>
class Character
{
public:
std::string m_name; // data member
std::string m_city; // data member
std::string m_weapon; // data member
int m_age; // data member
void Display(); // member function
Character(); // class constructer
};
int main()
{
Character player1;
std::cout << "Character Name: ";
getline(std::cin, player1.m_name);
std::cout << "Characters Home town: ";
getline(std::cin, player1.m_city);
std::cout << "Character Primary Weapon: ";
getline(std::cin, player1.m_weapon);
std::cout << "Character's Age: ";
std::cin >> player1.m_age;
player1.Display();
return 0;
}
// everytime a new instance of the class Character is created, this is called.
Character::Character()
{
std::cout << "Welcome to the Character Creation Room!\n\n";
}
void Character::Display()
{
system("cls");
std::cout << "////////////////////////////\n"
<< "// //\n"
<< "// Character Profile //\n"
<< "// //\n"
<< "////////////////////////////\n\n";
std::cout << "Character's Name = " << m_name << std::endl
<< "Character's Home town = " << m_city << std::endl
<< "Character's Weapon = " << m_weapon << std::endl
<< "Character's Age = " << m_age << std::endl << std::endl;
}
Code::Blocks Questions
Hello,
I've been working in c++ with vc++ express edition for about 4 months now, and have recently downloaded code::blocks. This IDE seems pretty cool, but I need some help.
Questions:
1: How do I create a new file with code::blocks? In VC++ Express it was easy, but in code::blocks, i cannot seem to figure out how to do it. (how pathetic)
2: I coded a little practice code about what i just learned about classes. The code works when i compile it in vc++ express, no errors, no warnings, but in Code::Blocks, it compiles fine, but i get a warning. It says, "main.cpp:57:2: warning: no newline at end of file". line 57 is the last line of code BTW.
The warning means just what it says, it wants an empty line at the end of the file. Totally useless warning in my view, but hey, whatever it wants.
To make a new file in codeblocks, you can click File->New File, press ctrl-N or click the blank page button up the top left [smile].
To make a new file in codeblocks, you can click File->New File, press ctrl-N or click the blank page button up the top left [smile].
About the warning, take a look at this thread for info.
If you still don't want to add the newline at the end of file manually, there are two ways to overcome this:
1) Ask gcc to not produce a warning about this: add "-Wno-eof-newline" in compiler options.
or
2) Ask Code::Blocks to do it automatically for you: just check the "Settings->Editor->End-of-line options->End files with blank line" option :).
If you still don't want to add the newline at the end of file manually, there are two ways to overcome this:
1) Ask gcc to not produce a warning about this: add "-Wno-eof-newline" in compiler options.
or
2) Ask Code::Blocks to do it automatically for you: just check the "Settings->Editor->End-of-line options->End files with blank line" option :).
Quote:Original post by RAZORUNREAL
The warning means just what it says, it wants an empty line at the end of the file. Totally useless warning in my view, but hey, whatever it wants.
To make a new file in codeblocks, you can click File->New File, press ctrl-N or click the blank page button up the top left [smile].
I tried doing this, but when i do, i cannot build the file. I have no clue why, but the build icon is faded out so i cannot click it. The only way i can build a .cpp file is if i create a new project.
I don't have Code::Blocks handy, but you probably need to add the file to the project in addition to creating it. Look for options relating to that. try right-clicking when focused on the file. Hope that helps.
EDIT: Wait I think I misread the question.
You haven't created a project, you just want to compile a single cpp file?
EDIT 2: I think in code::blocks they require you have a project for any cpp file you wish to compile. This is why I usually have a few dummy projects I use for quick testing so I don't have to keep making new pojrects
EDIT: Wait I think I misread the question.
You haven't created a project, you just want to compile a single cpp file?
EDIT 2: I think in code::blocks they require you have a project for any cpp file you wish to compile. This is why I usually have a few dummy projects I use for quick testing so I don't have to keep making new pojrects
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement