# Code::Blocks Questions

## Recommended Posts

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.
// 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;
}



##### Share on other sites
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].

##### Share on other sites

If you still don't want to add the newline at the end of file manually, there are two ways to overcome this:

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 :).

##### Share on other sites
Quote:
 Original post by RAZORUNREALThe 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.

##### Share on other sites
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

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627675
• Total Posts
2978571

• 11
• 11
• 10
• 12
• 22