所以我試圖創建一個Befunge interperter並將一個文本文件讀入一個數組。 我使用這個代碼:將一個std :: string放入一個char [] []數組
char map[100][100]; //not 85 x 20
//load the source
ifstream f;
f.open("file.txt", ios::in);
string s;
int i = 0;
while(f.good() && i < 100)
{
getline(f, s);
map[i] = s.c_str();
i++;
}
這是不行的,沒有人知道一個辦法做到這一點,而不通過串手動循環?
但是你明白_why_它不起作用嗎?這很重要... – ildjarn 2012-02-10 23:09:50
使用'strcpy'並注意緩衝區溢出。你不能分配給一個數組。或者甚至更好,使用'std :: vector'而不是yacky C字符串 –
2012-02-10 23:10:08
任何你不能使用'std :: vector'或者甚至是'std :: string [100]'的原因?如果您使用C++,請利用其類型! –
2012-02-10 23:14:44