誰かがこの短いプログラムやその他のひどいプログラムに対してg ++が私に与えるコンパイルエラーを修正する方法を教えてもらえますか. 私は初心者です。ありがとう。私は自分が何をしているのかわからないので、それらのほとんどがそうであることを知っています.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main (int argc, char* argv[])
{
struct RGB {
float r;
float g;
float b;
};
int w = atoi(argv[1]);
int h = atoi(argv[2]);
vector<vector RGB > image;
image.resize(w);
for (int q = 0; q < w; ++q)
image[q].resize(h);
for (int i = 0; i < w; ++i){
for (int j = 0; j < h; ++j){
float col = float (((i & 0x08) == 0) ^ ((j & 0x08) == 0));
image[i][j].r = col;
image[i][j].g = col;
image[i][j].b = col;
}
}
string filename = string(argv[3]) + ".ppm";
ofstream file(filename);
file << "P3" << endl;
file << w << " " << h << endl;
file << "255" << endl;
for (int i = 0; i < h; ++i){
for (int j = 0; j < w; ++j){
float col = float (((i & 0x08) == 0) ^ ((j & 0x08) == 0));
file << image[i][j].r*255 << " ";
file << image[i][j].g*255 << " ";
file << image[i][j].b*255 << " ";
}
file << endl;
}
file.close();
return 0;
}
エラー:
hw1.cpp: In function ‘int main(int, char**)’:
hw1.cpp:24: error: template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main(int, char**)::RGB’
hw1.cpp:24: error: trying to instantiate ‘template<class _Alloc> class std::allocator’
hw1.cpp:24: error: template argument 2 is invalid
hw1.cpp:24: error: template argument 1 is invalid
hw1.cpp:24: error: template argument 2 is invalid
hw1.cpp:24: error: invalid type in declaration before ‘;’ token
hw1.cpp:25: error: request for member ‘resize’ in ‘image’, which is of non-class type ‘int’
hw1.cpp:27: error: invalid types ‘int[int]’ for array subscript
hw1.cpp:32: error: invalid types ‘int[int]’ for array subscript
hw1.cpp:33: error: invalid types ‘int[int]’ for array subscript
hw1.cpp:34: error: invalid types ‘int[int]’ for array subscript
hw1.cpp:39: error: no matching function for call to ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::string&)’
/usr/include/c++/4.2.1/fstream:596: note: candidates are: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/fstream:580: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.2.1/iosfwd:92: note: std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)
hw1.cpp:46: error: invalid types ‘int[int]’ for array subscript
hw1.cpp:47: error: invalid types ‘int[int]’ for array subscript
hw1.cpp:48: error: invalid types ‘int[int]’ for array subscript