0
ファイルから行を読み込み、ファイル内の行に基づいてASCIIシェイプを出力するプログラムを作成しています。例えば、この「S @ 6」は6×6 @の実線の二乗を意味する。私の問題は、ファイルから行を読むことができますが、ファイル内の文字をどのように区切って入力として使用するかわかりません。私はすでにシェイプを作るための関数を書いていますが、ファイルの文字を引数として渡すだけです。文字列からの文字の読み取りまたは文字列からの文字の取得
int main()
{
void drawSquare (char out_char, int rows, int width);
void drawTriangle (char out_char, int rows);
void drawRectangle (char out_char, int height, int width);
char symbol;
char letter;
int fInt;
string line;
fstream myfile;
myfile.open ("infile.dat");
if (myfile.is_open())
{
while (getline (myfile,line))
{
cout << line << '\n';
}
myfile.close();
}
else cout << "Unable to open file";
drawRectangle ('*', 5, 7);
}
'のstd :: strtok'はあなたの友達です(http://en.cppreference.com/w/cpp/string/バイト/ strtok) – GMichael
私はこの答えのオプション2をお勧めします:http://stackoverflow.com/a/7868998/4581301 – user4581301