Here is my code:
//test file
#include <iostream>
#include "stat.h"
#include "frequency.h"
using namespace std;
int main(){
cout << "helo"<< endl;
return 0;
}
When I try to compile, I get:
test.cc:7: error: expected unqualified-id before "using"
test.cc:7: error: expected `,' or `;' before "using"
Any idea what is going on here?
You probably missed the ; in the end of the header file.
It should look like this:
class frequency {
...
};
The problem is likely an error in the last line of frequency.h.
Related
When I'm trying to run a simple hello world script it sends this error message, Can anyone help me solving this issue?
[Running] cd "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\" && g++ helloworld.cpp -o helloworld && "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\"helloworld
helloworld.cpp: In function `int main()':
helloworld.cpp:9: error: expected primary-expression before "msg"
helloworld.cpp:9: error: expected `;' before "msg"
helloworld.cpp:11: error: expected primary-expression before "const"
helloworld.cpp:11: error: expected `;' before "const"
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `)' before '}' token
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `;' before '}' token
[Done] exited with code=1 in 0.233 seconds
This is the written code
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
I revised the code you have posted as well as added a piece of code to utilize the namespace std. Analyzing the output from your compiler it does seem that you may have not added a semi colon. Alternatively, it's not necessary to reference the std library when calling it's functions but it's up to your preference. It doesn't seem though to be an issue with your code either. Can you post the actual code you've attempted to compile because there doesn't seem to be an issue with this piece.
Revised Code:
#include <iostream>
using namespace std;
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
I am not sure what happened to my system, but now when I try to include boost/any.hpp in a program test.cc
#include <iostream>
#include <boost/any.hpp>
int main(int argc, char *argv[])
{
std::cout << "hello" << std::endl;
return 0;
}
using g++ -o test test.cc, I get the following error:
In file included from test.cc:2:0:
/usr/include/boost/any.hpp: In function 'ValueType boost::any_cast(boost::any&)':
/usr/include/boost/any.hpp:278:52: error: 'if_' in namespace 'boost::mpl' does not name a template type
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
^ /usr/include/boost/any.hpp:278:55: error: expected unqualified-id before '<' token
typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
^ /usr/include/boost/any.hpp:284:28: error: 'ref_type' does not name a type
return static_cast<ref_type>(*result);
Everything is fine when I remove the include to any.hpp. I am using boost-1.56.0 and gcc-4.9.3.
Things were compiling fine a week ago, but I am not sure what I might have updated to cause this error. Any help would be appreciated.
I have seen a few questions on this error, but I don't have much experience with making a class in C++, so I don't actually understand what the answers mean. I should also point out that I didn't write this code.
I'm getting the error stated in the title, and I believe it's coming from this header file, but I have no idea what the error means and how to fix it.
Here is the file:
#ifndef _QUICKTIMER_H_
#define _QUICKTIMER_H_
#include <cstdlib>
#include <string>
#include <chrono>
class QuickTimer {
public:
QuickTimer(const std::string& prefix = "");
~QuickTimer();
private:
std::chrono::high_resolution_clock::time_point mStartTime;
const std::string mPrefix;
};
#endif
and the full errors:
error: expected unqualified-id before ‘const’
QuickTimer(const std::string& prefix) :
^
error: expected ‘)’ before ‘const’
error: declaration of ‘~QuickTimer’ as non-member
~QuickTimer()
^
If anyone could explain to me what it means and what's going on, I'd really appreciate it, thanks!
Class name prefix are probably missing in the definition of your constructor and destructor. You should have something like that in a cpp file :
QuickTimer::QuickTimer(const std::string& prefix)
{
}
QuickTimer::~QuickTimer()
{
}
Today, after Slackware 13.37 installation, i've got the problem: default GCC 4.5.2 cannot compile my code. Now I study C++ by the Stephen Davis's book "C++ for dummies" and want to compile this:
#include <stdio.h>
#include <iostream.h>
int main(int nNumberofArgs, char* pszArgs[])
{
int nNCelsius;
cout << "Celsisus: ";
cin >> nNCelsius;
int nNFactor;
nNFactor = 212 - 32;
int nFahrenheit;
nFahrenheit = nNFactor * nNCelsius / 100 + 32;
cout << "Fahrenheit: ";
cout << nFahrenheit;
return 0;
}
But my GCC 4.5.2 gives these errors:
FahTCel.cpp:7:14: error: expected ')' before ';' token
FahTCel.cpp:7:14: error: 'main' declared as function returning a function
FahTCel.cpp:8:1: error: 'cout' does not name a type
FahTCel.cpp:9:1: error: 'cin' does not name a type
FahTCel.cpp:12:1: error: 'nNFactor' does not name a type
FahTCel.cpp:15:1: error: 'nFahrenheit' does not name a type
FahTCel.cpp:17:1: error: 'cout' does not name a type
FahTCel.cpp:18:1: error: 'cout' does not name a type
FahTCel.cpp:20:1: error: expected unqualified-id before 'return'
FahTCel.cpp:21:1: error: expected declaration before '}' token
Three errors:
The correct header is <iostream>. This program requires no other headers.
You must either put using namespace std; in the file, or refer to std::cout and std::cin explicitly. Take your pick, plenty of C++ programmers disagree about which of the two options is better. (You could also bring just cin and cout into your namespace, if you wanted.)
The program does not write a line terminator at the end. This will cause the output to "look bad" on most terminals, with the command prompt appearing on the same line as the output. For example:
Here are the corrections:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
...
cout << nFahrenheit << '\n';
...
}
Note: It is extremely unusual to see main take parameters with names other than argc and argv. Changing the names just makes it harder for other people to read your code.
its std::cout or you should add using namespace std;
and the include should be < iostream> not < ionstream.h>.
The File is at the location /home/shivang/Desktop and the filename is sh1.cpp
Source code for the file is given below
#include iostream
#include json/json.h
#include json/reader.h
using namespace std;
using namespace Json;
int main() {
std::string example = "{\"array\":[\"item1\", \"item2\"], \"not an array\":\"asdf\"}";
Value value;
Reader reader;
bool parsed = reader.parse(example, value, false);
std::cout << parsed;
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
The following error messages are displayed.
/home/shivang/Desktop/sh1.cpp: In function ‘int main()’:
/home/shivang/Desktop/sh1.cpp:10:2: error: ‘Value’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:10:8: error: expected ‘;’ before ‘value’
/home/shivang/Desktop/sh1.cpp:11:2: error: ‘Reader’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:11:9: error: expected ‘;’ before ‘reader’
/home/shivang/Desktop/sh1.cpp:13:16: error: ‘reader’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:13:38: error: ‘value’ was not declared in this scope
Configuration gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
jsoncpp-src-0.5.0
eclipse-cpp-helios-SR2-linux-gtk
I have never used Json or C++ before. But a little googling around led me to this page. I think adding the following line to your list of includes should help:
#include <json/value.h>