我要做一個小 function, 每次從 檔案 讀進一筆 string, 然後宣告一個指向 char
的 array of pointers, 來儲存指向這每一筆 string 的 pointer, 可是下面這一小段
程式 always 指向目前的 string, (我從 Visual C++ 的 debugger 看到的 ),
要怎麼寫才會對 ?
void Proc_File( char *Fname_Array[ MAX ] )
{
ifstream inputfile( FILE, ios::in );
int j ;
char Fname1[ MAX ];
if ( !inputfile )
{
cerr << "File could not be opened " << endl;
exit( 1 );
}
j = 0;
while ( inputfile )
{
inputfile >> Fname1;
Fname_Array[ j ] = Fname1;
j++;
}
}
(我的意思是: 假設 inputfile 裡面的內容是:
Cook
Barry
Chris
xxxxxx
我要讓:
Fname_Array[0] = pointer(address) to "Cook"
Fname_Array[1] = pointer(address) to "Barry"
Fname_Array[2] = pointer(address) to "Chris"
Fname_Array[3] = pointer(address) to "xxxxxx"
好不好 ? 教我一下, 我可以理解上面那段 code 不對, 可是我不知道怎麼改....)
多謝囉~~~~
--
戰 14 場, 7 敗, 3 勝, 等消息 4....
assert() 的意思是讓程式“死得比較好看”
反正左右都是死 不加也說得過去【我只是開玩笑別當真】
看看有沒有 assert.h 現在在家裡沒工具 沒有的話問問別人吧﹗
: char *Fname1;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: > j = 0;
: > while ( inputfile )
: > {
: Fname1 = new char[MAX];
: assert(Fname1);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
謝謝 ctang, 關鍵就在這幾行, 我剛剛從 Visual C++ 的 debugger 去看結果, 程式已經
對了...
能不能順便請教一下, 如果要用 assert(), 需要 include 什麼樣的 header file 或
template 之類, 因為我若加上 assert 那一行, Visual C++ 的 compiler 不讓我過耶~~
assert(Fname1) --> ASSERT(Fname1)
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
Please be aware of following... :)
ASSERT() :This function is available only in the Debug version of MFC
^^^^^^^^
assert() is an ANSI macro.
^^^^^
assert prints a diagnostic message when expression evaluates to false (0)
and calls abort to terminate program execution. No action is taken if
expression
is true (nonzero). The diagnostic message includes the failed expression and
the
name of the source file and line number where the assertion failed.
> assert() is an ANSI macro.
> ^^^^^
> assert prints a diagnostic message when expression evaluates to false (0)
> and calls abort to terminate program execution. No action is taken if
> expression
> is true (nonzero). The diagnostic message includes the failed expression and
> the
> name of the source file and line number where the assertion failed.
Oops... 寫反了
大概時運不濟 昨天和 advisor 吵了一天
結果所有昨天的 post 都有錯 .... :(
不知道這和昨天 syracuse 輸球有沒有關係 ???
【P.S. 不過我吵贏了 :)】
>> assert() is an ANSI macro.
function
不過在 VC 裡 assert() 是 marco 用來包 _assert() function