0

これはコードです:

#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>

int main()
{
      char str1[100];
      char str2[100];
      getline(str1,100,'\n');
      getline(str2,100,'\n');
      return 0;
}

文字列を読み取って配列に格納したいので、このメソッドを使用していますが、コンパイル時に次のエラーが表示されます

   [Error]138: error: `getline' was not declared in this scope

配列内の文字列を読み取る方法は?

4

2 に答える 2

5

getline(名前空間cinに属する)のメンバーです。stdあなたは言う必要があります:

std::cin.getline(...)

テスト

私は個人的にこれをお勧めしますが:

#include <string>
#include <iostream>

int main()
{
    std::string str1;
    std::string str2;
    std::getline(std::cin, str1);
    std::getline(std::cin, str2);
    return 0;
}
于 2013-07-05T12:56:55.237 に答える