Image::Image() : p_hauteur, p_largeur
Image::Image() : p_hauteur(0), p_largeur(0)
#ifndef DEF_IMAGE #define DEF_IMAGE #include <string> #include // std::cin, std::cout, std::endl #include <fstream> #include <conio.h> #include <stdio.h> #include <map> #include <ctime> #include <vector> class Image { public: std::string nom_image; std::string ident; std::string image_sauvegardee; std::string action; std::vector<std::vector<double> > tabPix; char unoctet; double m_i, m_j, m_hauteur, m_largeur, m_pixel_maxi; void chargement(); }; #endif
#include "Image.h" using namespace std; /////////////////////////////////////////////////////////////////////////////// ////////////////////////////// Chargement ///////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // Fonction qui permet de charger/lire l'image initiale void Image::chargement() { //char unoctet; cout << "\nEntrez le nom de l'image" << endl; // l'image storm est P2 cin >> nom_image; // voir le mode HEX des visionneuse ifstream fin (nom_image.c_str()); fin >> ident; if (ident == "P5") { cout << "\ntype d’image non trait\202e" <<endl ; return ; // modifier selon le type } fin.get(unoctet); fin >> m_largeur >> m_hauteur; fin >> m_pixel_maxi; for (m_i = 0; m_i<m_hauteur ; m_i++) { for (m_j = 0; m_j<m_largeur; m_j++) { fin >> tabPix[m_i][m_j]; } } cout<<"Image charg\202e"<<endl; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionfor (m_i = 0; m_i<m_hauteur ; m_i++) { for (m_j = 0; m_j<m_largeur; m_j++) { fin >> tabPix[m_i][m_j]; } }
std::vector<std::vector<double> > tabPix;
std::vector<double> tab; tab.push_back(5); tab.push_back(6); tab.push_back(7);
std::vector<double> tab; tab.resize(3); tab[0] = 5; tab[1] = 6; tab[2] = 7;
std::vector<std::vector<double> > matrix; std::vector<double> tab; tab.push_back(5); tab.push_back(6); tab.push_back(7); matrix.push_back(tab); tab.clear(); // Vide le tableau tab.push_back(8); tab.push_back(9); tab.push_back(4); matrix.push_back(tab);
std::vector<std::vector<double> > matrix; matrix.resize(2); matrix[0].resize(3); matrix[1].resize(3); matrix[0][0] = 5; matrix[0][1] = 6; matrix[0][2] = 7; matrix[1][0] = 8; matrix[1][1] = 9; matrix[1][2] = 4;
Dans les .h, il est recommandé de ne jamais mettre la directive using namespace std; car cela pourrait avoir des effets néfastes lorsque vous utiliserez la classe par la suite.
Par conséquent, il faut rajouter le préfixe "std::" devant chaque string du .h. Sinon, le compilateur vous sortira une erreur du type "string does not name a type".
Donc selon toi, je n'ai pas besoin du tout de using namespace std ?