c++
1#include <fstream> 2#include <iostream> 3#include <string> 4#include <vector> 5using namespace std; 6 7int main() { 8 ifstream ifs("test.txt"); 9 char str[256]; //一行を読み込ませる用の配列 10 vector<vector <char>> text; //複数行を読み込ませる用の配列 11 if (ifs.fail()) { 12 cerr << "失敗" << endl; 13 return -1; 14 } 15 while (ifs.getline(str, 256 - 1)) { 16 text.push_back(str);//ここにエラーが出る 17 } 18 return 0; 19}
例えば"text.txt"の中身が
"text.txt"
あいうえお
かきくけこ
だとしたら
text[0][] = "あいうえお"
text[1][] = "かきくけこ"
という格納をしたいです。
どのようにやればよろしいでしょうか?
よろしくお願いいたします。
環境
xcode 9.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/15 04:06