What is wrong with this C++ Code? [closed]
i am a beginner and i have a problem :
this code doesnt compile :
main.cpp:
#include <stdlib.h>
#include "readdir.h"
#include "mysql.h"
#include "readimage.h"
int main(int argc, char** argv) {
    if (argc>1){
    readdir(argv[1]);
  //  test();
    return (EXIT_SUCCESS);
    }
    std::cout << "Bitte Pfad angeben !" << std::endl ;
    return (EXIT_FAILURE);
}
readimage.cpp
#include <Magick++.h>
#include <iostream>
#include <vector>
using namespace Magick; using namespace std;
void readImage(std::vector<string> &filenames) {
    for (unsigned int i = 0; i < filenames.size(); ++i) {
        try {
            Image img("binary/" + filenames.at(i));
            for (unsigned int y = 1; y < img.rows(); y++) {
                for (unsigned int x = 1; x < img.columns(); x++) {
                    ColorRGB rgb(img.pixelColor(x, y));
                    // cout << "x: " << x << "   y: " << y << " : "  << rgb.red() << endl;
                }
            }
            cout << "done " << i << endl;
        } catch (Magick::Exception & error) {
            cerr << "Caught Magick++ exception: " << error.what() << endl;
        }
    } }
readimage.h
#ifndef _READIMAGE_H
#define _READIMAGE_H
#include <Magick++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace Magick;
using namespace std;
void readImage(vector<string> &filenames)
#endif  /* _READIMAGE_H */
If want to compile it with this code :
g++ main.cpp
Magick++-config --cflags --cppflags --ldflags --libsreadimage.cpp
i get this error message :
main.cpp:5: error: expected initializer before ‘int’
i have no clue , why ? :(
Can somebody help me ? :)
In readimage.h, you are missing a semicolon after your readImage function declaration.
One of the first things you should do when compiling for the first time is to try one piece of code at a time. Don't throw a bunch of code together and hope that it compiles. Instead, take it one fragment at a time. So here, you might comment out your includes and the code that you expect to use the stuff in those files.
At first glance, it looks like
void readImage(vector<string> &filenames)
is missing a semicolon at the end of the line, since you're declaring it.
In readImage.h, you're missing a semicolon after the readImage function prototype.
This function declaration:
void readImage(vector<string> &filenames)
is missing a semicolon at the end. An unrelated issue - your include guard names:
#ifndef _READIMAGE_H
are illegal. Names that begin with an underscore and an uppercase letter are reserved in C++ - you are not allowed to create such names yourself.
And in your loop:
for (unsigned int y = 1; y < img.rows(); y++) {
are you sure you should be beginning the loop at 1 and not at zero?
; is missing at the end of readimage.h
Since, main.cpp is pre-processed first, it finds the error at the last line of readimage.h and shows that error occurred before int in main.cpp  
main.cpp:5: error: expected initializer before ‘int’
You just need a semicolon at the end of readImage declaration in readimage.h:
void readImage(vector<string> &filenames);
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论