C++ compiler error message - c++

Im still new to programing, ive started a draft project and coppied the code into anther project but when i try to debug i get this error message i dont know whats going on. Can anyone help me please ?
// this is my code
#include "Questions.h"
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
ofstream myfile;
myfile.open ("Questions.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
The error says
error C1075:end of file before the left brace '{' at
#questions.cpp(10) was matched

The error message is self explanatory.
Take a look at the code in questions.cpp, where does the main function end? (Keep in mind that the header files are included verbatim, so make sure that the header file has the same number of {'s as it has for }'s, and that they aren't #ifdef'ed out.) The comments provided by Victor Sand, dasblinkenlight, and Hot Licks are all good.
Your code as it stands is not using Questions.h at all (any more, now that you've commented out the majority of the implementation), so try commenting that include out and then testing. If it passes, the problem is in Questions.h.

Your problem is more than likely coming from Questions.h
If you check that file you'll more than likely see no } at the end.

Related

Trying to close c++ program at certain time returns value's (that i don't want)

Running the code returns no errors, the problem is when I try to exit the program.
Simply, when i use the exit, return or abort functions, i get this (picture below)
see code below
//First 2 libs handle info exchange
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
using namespace std;
main(){
string username;
cout << "Please enter a general use handel (\"username\")\n";
cin >> username;
fstream blockUsername;
blockUsername.open("Player_Data/username.txt", ios::out); //out is for writing, in is for reading
blockUsername << username;
blockUsername.close();
return 0;
}
I'm aware that similar questions have been asked, but I have not succeeded in fixing my code with those.
What I want is for the program to close with no exit values, even though I know that they are useful.
PS: It very well could be something to do with my code editor (Dev C++), or my compiler which i broke and had to fix recently.
Also side note how would i go about removing that address at the top of the terminal (and potentially replacing it with something else)?
These are printed by your IDE....if u execute the .exe output of this code...the console would just disappear after program exits and it would not be shown
Peace
try using return 0; wherever you want to exit, it's okay to have more than one return 0; in your code or to simply put it after an if statement.

Eclipse C++ "#include" and "using namespace" errors

My aunt gave me a book about c++ (for beginners). It's nice and so I wanted to test one of those code samples. But I am just getting errors. I didn't find anything that could help me on Google or so.
I am using Eclipse Mars.1 C++ and MinGW.
Code:
/*
* Erstes_Programm.cpp
*
* Created on: 26.12.2015
* Author: Luca
*/
// Erstes Programm
#include <iostream>
using namespace std;
int main() {
cout << "It's just a test!" << endl;
return 0;
}
I am getting those errors:
Using namespace:
Description Resource Path Location Type
expected ';' before ':' token
Erstes_Programm.cpp /Programmieren C++ (Einführung)
line 10
C/C++ Problem
AND
Description Resource Path Location Type
expected unqualified-id before ':' token
Erstes_Programm.cpp /Programmieren C++ (Einführung)
line 10
C/C++ Problem
Hope somebody can help me?
Here is a screenshot:
EDIT: PROBLEM SOLVED!! I don't know WHAT I did, but it's solved I'm not getting any errors and everything works perfectly. Thanks for everybody who wanted to help
The first line in the screenshot doesn't make any sense. Remove it. The rest looks fine. And in the future, post text, not screenshots.
Instead work on X-code rather then eclipse for C++. Visual studio is most recommend.
For Your problem, I think you got to play with the library, something must not be supported, other then that your code look fine.

Weird compiling error with CodeBlocks - c++

that's my first use to code block but it hasn't gone fine ,, i face a really weird problem
i cant even describe it so i will just tell you what's happened.
the problem is that the ide dont compile my project even if the code were correct
its just open a new tab that called "iostream" and the console window appears but empty
why do that happens ?
look to the code which the ide face a problem while compiling it ,, simplest code ever
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
and this is the compiling results...
thats all..
will codeblocks stop annoying me ?
This line is not valid syntax
usingnamespace std;
Those are two separate keywords
using namespace std;
And since you are just starting C++, Lesson 1: Don't do that.

Beginner questions about vim

Question #1:
if I have a C++ code like this
#include <iostream>
using namesapce std;
int main() {
int a;
cin >> a;
cout << a << endl;
return 0;
}
I don't know if this is called (debugging, compiling, or building), but I just want to run this program inside gvim so I can give it the input and see the output, and see errors such as "missing ';' " or "missing '}' " (like what happens when I click F9 in "Code::Blocks").
exe file, and other things are not important for me.
Question #2:
if I have a C++ code that I write every time like this
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
How can I make vim insert this code every time I open a .cpp file with vim ?
I have Windows 7 32-bit and my .vimrc file is the default one that comes when I install vim.
Please be as detailed as possible.
Probably this is what you are looking for
Vi and Vim Autocommand: 3 Steps to Add Custom Header To Your File Automatically
Q1: You'll need to compile your C++ code first to "see errors such as "missing ';' " or "missing '}'". Then you can run your compiled EXE to determine if your input and output values work. In Visual Studio, hitting the play button (Debug) will do both.
Q2: vim has a set of events that occur that allow you to perform certain actions, like append text to a new file with an extension of .cpp. You would add some code to your .vimrc file to do this.
If you just want it on opening up use autocmd. You can do it like lipun4u said:
Vim autocommand auto add headers at start of file
Well I suggest getting this plugin: snipMate
snipMate.vim aims to be an unobtrusive, concise vim script that implements some of TextMate's snippets features in Vim. A snippet is a piece of often-typed text that you can insert into your document using a trigger word followed by a tab.
It has several features:
More than 1 language supported
Lots of premade snippets
Ability to make your own snippets
So this way you can have different headers for different programs, and just assign them to a hot key.

C++: Unable to resolve identifier cout, Netbeans, Ubuntu

I am using C++ on Netbeans 7.1 on Ubuntu 11.04. For some reason, the following code results in the error message "Unable to resolve identifier cout".
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello,world!\n";
return 0;
}
Any help resolving this problem would be greatly appreciated.
The solution for your problem is at least strange ;)
Once iostream header is added, one has to reparse code. Click right on a project, go to code assistance and click to reparse project. Worked for me.
I was using netbeans for mac.
check whether iostream is really getting included;
i have tried your code on my machine using eclipse cdt it worked fine.so, please check the
includes.
What sort of file is this in? Is it a .h file, or .hpp file? I had this same issue. Netbeans can be ridiculous sometimes with C++. For me, I changed #include <iostream> to #include<iostream.h>
This may seem too simple, but...
In my NetBeans installation, when I go to create a new project, specify C/C++, it brings up a dialog box prompting for "Project Name:", location, folder, makefile name, and then...
a check box for "Create Main File", an edit box with "main" filled in, and to the right of that is a drop down list that reads "C". If you hit Finish, this will create "main.c" (C, but NOT a C++ file). Instead, in the drop down list, select "C++". Then the IDE creates main.cpp, which will be compiled with g++ and will find those includes and functions.
There is a difference between std::cout and cout. You don't currently have std::cout defined in your file. std::cout is a c standard out. In C++ we only need cout to work with iostream.
If you must use a standard c out then do the following:
Add this to the top under iostream
#include <iostream> //Input output stream in C++
#include <cstdlib> //Stands for c standard library
using namespace std;
Your code will now work because:
This change defines std::cout and std::cin among other things. (standard in, standard out respectively.)
However, I'd recommend this alternative if you don't need standard in outs:
Replace std::cout with cout, because cout is defined in iostream in C++. Your program would have worked without the std:: portion of your cin cout commands because you originally included iostream.
Try taking out the using namespace std; - it's generally considered bad form anyway :-)
I'm not sure that will fix the problem but most people either use the namespace or fully qualify things like std::cout. I've never seen code that does both.
The other thing to check is that the iostream header actually is being bought in. In other words, are there any errors on that line. A lot of problems (at least in the Windows world, so it may not necessarily apply to you) seem to be due to faulty path setup in NetBeans.
Hey look at your Output Debug. You may see "no permission". After I changed the file permission of "/YourProjekt/dist/Debug/GNU-Linux/file" to runable and everyone can read and write the error disappeared. (BTW: I had the bug because I was on a NTFS System with my Projekt, it have to be ext partition)
Hope I can help you with that.
Try taking out the std:: next to cout