エラーがとれません 助けてください

このQ&Aのポイント
  • コンパイル時にエラーが発生しています。eval4.cppファイルの105行目と114行目で'strlen'と'strchr'関数が未定義とされています。
  • また、eval4.cppファイルの132行目から134行目では、文字列定数を'char*'に変換する際に廃止された変換が行われています。
  • Ubuntuのg++でコンパイルしているため、エラーが発生している可能性があります。
回答を見る
  • ベストアンサー

エラーがとれません 助けてください

エラーがとれません 助けてください http://cs.fit.edu/~mmahoney/dist/eval4.cpp をコンパイルすると eval4.cpp: In member function ‘bool Attack::read(FILE*)’: eval4.cpp:105: error: ‘strlen’ was not declared in this scope eval4.cpp:114: error: ‘strchr’ was not declared in this scope eval4.cpp: In function ‘int main(int, char**)’: eval4.cpp:132: warning: deprecated conversion from string constant to ‘char*’ eval4.cpp:133: warning: deprecated conversion from string constant to ‘char*’ eval4.cpp:134: warning: deprecated conversion from string constant to ‘char*’ eval4.cpp:183: error: ‘strlen’ was not declared in this scope のようなエラーがでてしまいます。 Ubuntuのg++でコンパイルしています。 なにがまずいのでしょうか?

noname#182748
noname#182748

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

そのまんまですね。 > eval4.cpp:105: error: ‘strlen’ was not declared in this scope strlenが宣言されていない。 →cstringのインクルードが必要。 > eval4.cpp:132: warning: deprecated conversion from string constant to ‘char*’ 文字列定数 (const charの配列) からchar *への変換は廃止予定 →文字列定数はconst char *で受ける。 # 警告なので無視してもよいが,文字列定数の領域を変更することは未定義動作なので注意。

関連するQ&A

  • C++コンパイルエラーの原因を教えてください

    Cには詳しいのですが、C++があまりよくわかっておらず、質問させてください。 今回、手に入れたC++のあるプログラムをmakeしています(x86_64 Linux)。 以下のようなエラーが出てコンパイルできないのですが、何が悪いのか全く理解できず困っています。 他の環境ではコンパイルできているらしいので、わたしの環境の何が悪いのか、考えられることがありましたら、何でも書き込んでいただけると嬉しいです。 よろしくお願いします。 g++ -c -I../MathUtils -I../CommonUtils -DHAVE_ZLIB -DHAVE_BZLIB -fomit-frame-pointer -O2 -DFTYPE=float -Wall -Wsign-compare -Wpointer-arith -pedantic -DHAVE_PGPLOT -I. -DHAVE_FFTW -o analyse_image.o analyse_image.cpp In file included from analyse_image.cpp:21: Tools.h:16:15: warning: anonymous variadic macros were introduced in C99 analyse_image.cpp: In function ‘int main(int, char**)’: analyse_image.cpp:114: error: ‘strcmp’ was not declared in this scope analyse_image.cpp:205: error: ‘exit’ was not declared in this scope analyse_image.cpp:209: error: ‘strstr’ was not declared in this scope analyse_image.cpp:216: error: ‘exit’ was not declared in this scope analyse_image.cpp:457: error: ‘strlen’ was not declared in this scope make: *** [analyse_image.o] Error 1

  • wxGladeで生成したhello.cpp&hello.hファイルをコンパイルしようとするとエラーが出ます

    http://0xcc.net/pub/uu-2004-08/ や http://d.hatena.ne.jp/foral/20061224 を見て、wxGladeで生成したhello.cpp&hello.hファイルをMSYSのコンソールから g++ -c hello.cpp 'wx-config --cxxflags --libs' でコンパイルしようとしたのですが、以下のようなエラーが出てコンパイルできません。 環境はWindows XP MinGW&MSYS wxWidgets2.8.7 (パスは、C:\msys\1.0\home\owner) です。 普通のC++ファイルのコンパイルは出きるのですがwxWidetsが絡むとできないようです。 In file included from hello.cpp:3: hello.h:3:10: #include expects "FILENAME" or <FILENAME> hello.h:4:10: #include expects "FILENAME" or <FILENAME> In file included from hello.cpp:3: hello.h:13: error: expected class-name before '{' token hello.h:18: error: expected `)' before '*' token hello.h:28: error: ISO C++ forbids declaration of `wxStaticText' with no type hello.h:28: error: expected `;' before '*' token hello.h:29: error: ISO C++ forbids declaration of `wxPanel' with no type hello.h:29: error: expected `;' before '*' token hello.cpp:6: error: expected `)' before '*' token hello.cpp: In member function `void MyFrame::set_properties()': hello.cpp:22: error: `wxT' was not declared in this scope hello.cpp:22: error: `SetTitle' was not declared in this scope hello.cpp: In member function `void MyFrame::do_layout()': hello.cpp:30: error: `wxBoxSizer' was not declared in this scope hello.cpp:30: error: `sizer_1' was not declared in this scope hello.cpp:30: error: `wxBoxSizer' is not a type hello.cpp:30: error: `wxVERTICAL' was not declared in this scope hello.cpp:31: error: `sizer_2' was not declared in this scope hello.cpp:31: error: `wxBoxSizer' is not a type hello.cpp:31: error: `wxHORIZONTAL' was not declared in this scope hello.cpp:32: error: `label_1' was not declared in this scope hello.cpp:32: error: `wxFIXED_MINSIZE' was not declared in this scope hello.cpp:33: error: `panel_1' was not declared in this scope hello.cpp:37: error: `wxEXPAND' was not declared in this scope hello.cpp:38: error: `SetAutoLayout' was not declared in this scope hello.cpp:39: error: `SetSizer' was not declared in this scope hello.cpp:42: error: `Layout' was not declared in this scope hello.cpp: At global scope: hello.cpp:48: error: expected class-name before '{' token hello.cpp:55: error: expected constructor, destructor, or type conversion before "bool" g++.exe: wx-config --cxxflags --libs: No such file or directory 解決方法が分かる方いらっしゃしましたらご教示頂けると幸いです。

  • C++(というよりC)で文字を置換

    現在じゃんけんさせるプログラムを作っています。その中で 0→ぐー 1→ちょき 2→パー のように変換してreturnさせる関数を作りたいのです。 現状作ったファイルをコンパイルすると VisualStudioだと エラー 1 error C2440: 'return' : 'char [20]' から 'int' に変換できません。 27 1 じゃんけん・改 2 IntelliSense: 戻り値の型が関数型と一致していません 27 9 じゃんけん・改 g++だと In function 'int Replacement(int)': 19:20: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] char *Replaced = "パー"; ^ 22:20: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] char *Replaced = "ちょき"; ^ 25:20: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] char *Replaced = "ぐー"; ^ 27:9: error: invalid conversion from 'char*' to 'int' [-fpermissive] return Replaced; ^ 17:7: warning: address of local variable 'Replaced' returned [-Wreturn-local-addr] char Replaced[20] = { 0 }; ^ In function 'int main()': 60:27: error: 'scanf_s' was not declared in this scope scanf_s("%d", &player_c); とエラーやら警告がでます。g++のscanf_sのエラーはscanfにすればいいので気にしないとして、どうすれば目的の関数が作れますか? [ソース抜粋] int Replacement(int ver){ char Replaced[20] = { 0 }; if (ver == 2){ char *Replaced = "パー"; } else if (ver == 1){ char *Replaced = "ちょき"; } else{ char *Replaced = "ぐー"; } return Replaced; /*switch (ver){ case 2: char *Replaced = "パー"; return Replaced; break; case 1: char *Replaced = "ちょき"; break; default: char *Replaced = "ぐー"; break; }*/ } void Which_is_Winner(int player_c,int cpu_c, int Judge_Which_is_Winner){ printf("じゃんけん・・・・・・ポンっ!\n"); printf("あなた:%s\nCPU:%s\nじゃんけん", Replacement(player_c), Replacement(cpu_c));//それぞれの手を表示 if (player_c == Judge_Which_is_Winner){ printf("あなたの勝ちです!\n"); } else { printf("cpuの勝ちです!\n"); } }

  • lunuxでコンパイル

    普段はリヌックスの環境を使っているのですが、ウィンドウズでしか動かないプログラムがあり、プログラムを実行するたびに、マシンを切り替えていて不便を感じています。 http://prefixspan-rel.sourceforge.jp/のC++のファイルをリヌックスでコンパイルしたいのですが、g++ prefixspan.cpp では In file included from /usr/include/c++/4.4/backward/strstream:47, from prefixspan.cpp:30: /usr/include/c++/4.4/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. prefixspan.cpp: In function ‘int main(int, char**)’: prefixspan.cpp:492: error: ‘atoi’ was not declared in this scope となります。C++に関しては詳しくないのですが、これは直せるものなのでしょうか?

  • C++, strcpy の warning.

    VC2005 Express Edition を使ってます。 #include <iostream> #include <string> using namespace std; int main() {   char str[10] = "hello";   strcpy(str, "HELLO"); } ↑ こちらをコンパイルすると hello.cpp .\hello.cpp(8) : warning C4996: 'strcpy' was declared deprecated C:\Program Files\Microsoft Visual Studio 8\VC\include\string.h(73) : see declaration of 'strcpy' という警告が出るのはどうしてでしょうか? #include <string.h> も試したのですが同じ警告でした。

  • gccでコンパイル時のエラー

    // test.cpp #include <stdio> using namespace std; int main(int argc, char *argv[]) { printf("test\n"); return 0; } 上記コードをコンパイルしたいのですが make -k g++ -g -O2 -Wall -I. -c test.cpp -o test.obj test.cpp:2:17: stdio: No such file or directory test.cpp: In function `int main(int, char**)': test.cpp:7: error: `printf' was not declared in this scope test.cpp:7: warning: unused variable 'printf' make: *** [test.obj] Error 1 make: Target `all' not remade because of errors. となります。 #include <stdio> using namespace std; を #include <stdio.h> // using namespace std; にすれば正常に終了するのですがなぜでしょうか? gccはMingw5.1.6からインストールしたもので、 バージョンはgcc3.4.5です。 Meadow上から実行しました。 回答よろしくお願い致します。

  • C++でコンパイルするとwarningが出ます

    C++初心者です。 C++でコンパイルすると以下のようなwarningメッセージが出るのですが、どういう意味なんでしょうか?解決策があれば教えてください。 プログラム(sample.cpp) #include <iostream.h> main(){ cout << " sample \n"; } warningメッセージ In file included from /usr/include/c++/3.3.1/backward/iostream.h:31, from sample.cpp:1: /usr/include/c++/3.3.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider usin g one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <s stream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated

  • 箱庭諸島2+でコンパイルエラー

    Windows XP SP3 + GCC4.4.0を使っています。 「箱庭諸島の保管庫」というサイトから箱庭諸島2+をダウンロードしてきて、コマンドプロンプトから、解凍したディレクトリに移動し、makeを実行しました。すると、 g++ -c -O2 -Wall main.c In file included from main.c:1: main.h:5:21: error: iostream.h: No such file or directory In file included from main.h:6, from main.c:1: hako_io.h:5:20: error: fstream.h: No such file or directory In file included from info.h:7, from hako_io.h:12, from main.h:6, from main.c:1: value.h:30: error: 'ifstream' has not been declared In file included from hako_io.h:12, from main.h:6, from main.c:1: info.h:30: error: 'ifstream' has not been declared info.h:33: error: 'ofstream' has not been declared info.h:101: error: 'ifstream' has not been declared info.h:104: error: 'ofstream' has not been declared In file included from hako_io.h:14, from main.h:6, from main.c:1: map.h:32: error: 'ofstream' has not been declared map.h:35: error: 'ifstream' has not been declared map.h:185: error: 'ofstream' has not been declared map.h:188: error: 'ifstream' has not been declared In file included from hako_io.h:15, from main.h:6, from main.c:1: command.h:20: error: 'ifstream' has not been declared command.h:21: error: 'ofstream' has not been declared command.h:74: error: 'ifstream' has not been declared command.h:75: error: 'ofstream' has not been declared In file included from main.h:6, from main.c:1: hako_io.h:29: error: ISO C++ forbids declaration of 'ofstream' with no type hako_io.h:29: error: expected ';' before '*' token main.c: In function 'int main()': main.c:5: error: 'srandom' was not declared in this scope make: *** [main.o] Error 1 というエラーが出て、コンパイルされません。 原因はいったいどこにあるのでしょうか。 「ifstream」や「ofstream」といった単語が多く見られるので、そこがエラーの元だとは思うのですが… どなたか、知恵をお貸しいただけないでしょうか。

  • arduino due tone()について

    arduino due を使用しtone()関数を使用しようとしたところ ”tone was not declared in this scope”と表示されました。uno では使えたんですが・・・ 原因がわかる方教えてください。また、解決方法ありましたらそちらもご教授ください。

  • エラーが改善できません。

    C:\__Home\Visual Studio 2008\Projects\fecgsepfast>make MAKE Version 5.2 Copyright (c) 1987, 2000 Borland g++ -o fecgsep -O3 -lm ./src/fecgsep.cpp ./src/mem_util.cpp -L ./ -lica_ dll_amd ./src/fecgsep.cpp: In function 'int main(int, char**)': ./src/fecgsep.cpp:245:22: warning: name lookup of 'i' changed ./src/fecgsep.cpp:28:9: warning: matches this 'i' under ISO standard rules ./src/fecgsep.cpp:203:17: warning: matches this 'i' under old rules C:\DOCUME~1\Wada\LOCALS~1\Temp\cc6RcquX.o:fecgsep.cpp:(.text+0x41f): undefined r eference to `_imp___Z13fnica_dll_amdPdiiS_b' C:\DOCUME~1\Wada\LOCALS~1\Temp\cc6RcquX.o:fecgsep.cpp:(.text+0x718): undefined r eference to `_imp___Z13fnica_dll_amdPdiiS_b' collect2: ld returned 1 exit status ** error 1 ** deleting a.out というエラーが改善できません。どなたかアドバイスをお願いします。

専門家に質問してみよう