• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:下記、プログラム内の「char *」の役割)

プログラム内の「char *」の役割

dai_kの回答

  • dai_k
  • ベストアンサー率37% (3/8)
回答No.5

かなり適当ですみません。 私はいつもこんな風に使ってます。 とりあえず、見た目で理解できたらと思います。 LoadFile("test.wav");  //ファイルをロードする void LoadFile(char *FileName) { file = fopen(FileName, "r"); //ファイルを開く  PlayWave(file); //ファイルを再生する。 }

関連するQ&A

  • char型変数のアドレスを coutで表示するには

    #include <iostream> using namespace std; int main() { bool b; int i; short s; long l; float f; double d; char c; //上で宣言した変数のアドレスを表示 cout << "bool &b " << &b << endl; cout << "int &i " << &i << endl; cout << "short &s " << &s << endl; cout << "long &l " << &l << endl; cout << "float &f " << &f << endl; cout << "double &d " << &d << endl; cout << "char &c " << &c << endl; //「char &c 」とのみ表示される cout << '\n'; //char型のみ printf で再表示 printf("char &c %p\n", &c); //「char &c ********」と表示される return 0; } 上のプログラムを実行すると cout << "char &c " << &c << endl; のところだけ、アドレスが表示されません。 printfを使えば、char型の変数のアドレスも表示されるのですが…。 coutを使ってchar型のアドレスを表示させるにはどうすればいいのでしょうか。 よろしくお願いします。

  • プログラムの動作の仕方

    この下のプログラムは、WRITE <ファイル名>をコマンド行で入力すると、動作するプログラムなのですが、この通りにWRITE <test>としてもできません。 やり方を教えてください. #include <iostream> #include <fstream> using namespace std; int main(int argc,char *argv[]) { if(argc!=2){ cout << "使い方:WRITE<ファイル名>" << endl; return 1; } ofstream out(argv[1]); //出力ファイル if(!out){ cout << "出力ファイルが開けません" << endl; return 1; } char str[80]; cout << "文字列をディスクに書き込み、$で停止します" << endl; do{ cout << ": "; cin >> str; out << str << endl; }while(*str!='$'); out.close(); return 0; } お願いします。

  • C++で2点間の内積と距離を求めるプログラム

    C++で2点間の内積と距離を求めるプログラムを作ったのですが、コンパイルの時点でエラーが6つも出てしまいます>< 何がいけないのでしょうか? #include <iostream> #include <cmath> using namespace std; int main(void){ int x, y, z, w, l, n; cin >> x >> y >> z >> w; n=x*w+y*z;   l=sqrt((x-z)(x-z)+(y-w)(y-w)); cout << "距離は" << l << "で、内積は" << n; return 0; }

  • オブジェクト(メモリ)のアドレスについて

    ■C++言語を勉強中です。 ■ポインター関係でオブジェクトのアドレスを求めています。 ■参考にC言語とC++言語で求めてみました。 ■ところが、C++プログラムでchar型のアドレスが表示されません。 ■C言語では表示されます 「質問」理由が分かりません、C++初心者です、宜しくお願いします。 //オブジェクトのアドレス //C++言語 #include <iostream> using namespace std; int main() { char x;      int y; double z; cout << "xのアドレス :" << &x << '\n'; cout << "yのアドレス :" << &y << '\n'; cout << "zのアドレス :" << &z << '\n'; return 0; } /* //C言語 #include <stdio.h> int main() { char x; int y; double z; printf("xのアドレス :%p \n",&x); printf("yのアドレス :%p \n",&y); printf("zのアドレス :%p \n",&z); return 0; } */  

  • プログラムのどこがエラーか教えてください(C++)

    問題は、buildingという基本クラスを作って、建物の階数、部屋数、床の総面積を格納するクラスを作成し、次にhouseという派生クラスを作り、buildingを継承し、寝室数と、浴室数を格納するクラスで、officeという派生クラスを作り、これもbuildingを継承し、消火器台数と、電話台数を格納するクラスを作成し、それぞれの結果を出力せよ。っていう問題です。 下に僕が作成したプログラムを書きます。雑なので見にくいかもしれませんがお願いします。 #include <iostream> using namespace std; class building{ int Floor,Room,Area; public: building(int f,int r,int a){ Floor=f; Room=r; Area=a; } void get_FRA(int &f,int &r,int &a){ f=Floor; Room=r; Area=a; } }; class house:public building{ int Bedroom,Bathroom; public: house(int f,int r,int a,int Be,int Ba):building(f,r,a){ Bedroom=Be; Bathroom=Ba; } void Hshow(); }; class office:public building{ int FireExtinguisher,Telephone; public: office(int f,int r,int a,int fe,int t):building(f,r,a){ FireExtinguisher=fe; Telephone=t; } void Oshow(); }; void house::Hshow() { int x,y,z; get_FRA(x,y,z); cout << "階数:" << x << "階建て" << endl; cout << "部屋数:" << y << "室" << endl; cout << "床の総面積:" << z << "m2" << endl; cout << "寝室:" << Bedroom << "室" << endl; cout <<"浴室:" << Bathroom << "室" << endl; } void office::Oshow() { int x,y,z; get_FRA(x,y,z); cout << "階数:" << x << "階建て" << endl; cout << "部屋数:" << y << "室" << endl; cout << "床の総面積:" << z << "m2"<< endl; cout << "消火器の数:" << FireExtinguisher << "個" << endl; cout << "電話の数:" << Telephone << "個" << endl; } int main() { house H_ob(5,2,300,3,2); office O_ob(3,5,500,2,8); H_ob.Hshow(); O_ob.Oshow(); return 0; } あと、プログラムの処理結果を貼っておきます。 できれば、詳しく教えていただければ幸いです。

  • プログラムの動作

    10文字をスキップするプログラムなのですが、どのようにスキップしているのかわからないので教えてください。 下にソースコードを書きます。 #include <iostream> using namespace std; //10文字をスキップする istream &skipchar(istream &stream) { int i; char c; for(i=0; i<10; i++)stream >> c; return stream; } int main() { char str[80]; cout << "いくつかの文字を入力する:"; cin >> skipchar >> str; cout << str << endl; return 0; } よろしくおねがいします。

  • 実行

    こんにちは。私は昨日からC++を始めたのですがなかなかうまくいかないためこちらに質問させていただくことにしました。 #include <iostream.h> int main(void) { int x; int y; cout<<"xを入力: 10"; cin>>x; cout<<"yを入力: 2"; cin>>y; cout<<"x+yは"<<x+y<<"です。\n"; return(0); } このようなプログラムを作成したのですが実行してみたところ、 xを入力: 10 これ以降下までいきません。どうすればうまくいくのでしょうか?宜しくお願いします。

  • 共用体のサンプルコード : 内容がわかりません

    #include <iostream> using namespace std; union bits{ bits(double n); void show_bits(); double d; unsigned char c[sizeof(double)]; }; bits::bits(double n) { d = n; } void bits::show_bits() { int i, j; for(j = sizeof(double)-1; j>=0; j--){ cout << "バイト単位のビットパターン" << j << ":"; for(i=128; i ; i >>=1) if(i &c[j]) cout <<"1"; else cout << "0"; cout <<endl; } } int main () { bits ob(1991.829); ob.show_bits(); return 0; } このコードが何をしているのか解説していただけないでしょうか?

  • char *の書き換え

    #include <iostream.h> int main(){  char *p = "abcdef";  p[3] = 'g';  cout << p[3];  return 0; } C++です。 p[3] = 'g'; は、やってはいけないことですか?

  • 配列の逆順コピー

    for文を使って、配列xの並びを逆順にしたものを配列yにコピーするプログラムを作りたいのですがうまくいきません。どうすればよいでしょうか? #include<iostream.h> int main(void){ int i,j; int x[5]={1,2,3,4,5}; int y[5]; for(i=4;i>=0;i--){ for(j=0;j<5;j++){ x[i]=y[j]; } } for(j=0;j<5;j++) cout<<y[j]<<endl; return 0; }