代码如下:
//////////////////////////////////////////////////////////////////////
//
// Compile options needed: -GX
//
// insert.cpp :  Shows the various ways to insert elements into a
//               list<T>.
//
// Functions:
//
//    list::insert
//////////////////////////////////////////////////////////////////////#include <list>
#include <iostream>using namespace std ;typedef list<int> LISTINT;void main()
{
    int rgTest1[] = {5,6,7};
    int rgTest2[] = {10,11,12};    LISTINT listInt;
    LISTINT listAnother;
    LISTINT::iterator i;    // Insert one at a time
    listInt.insert (listInt.begin(), 2);
    listInt.insert (listInt.begin(), 1);
    listInt.insert (listInt.end(), 3);    // 1 2 3
    for (i = listInt.begin(); i != listInt.end(); ++i)
        cout << *i << " ";
    cout << endl;    // Insert 3 fours
    listInt.insert (listInt.end(), 3, 4);    // 1 2 3 4 4 4
    for (i = listInt.begin(); i != listInt.end(); ++i)
        cout << *i << " ";
    cout << endl;    // Insert an array in there
    listInt.insert (listInt.end(), rgTest1, rgTest1 + 3);    // 1 2 3 4 4 4 5 6 7
    for (i = listInt.begin(); i != listInt.end(); ++i)
        cout << *i << " ";
    cout << endl;    // Insert another LISTINT
    listAnother.insert (listAnother.begin(), rgTest2, rgTest2+3);
    listInt.insert (listInt.end(), listAnother.begin(), listAnother.end());    // 1 2 3 4 4 4 5 6 7 10 11 12
    for (i = listInt.begin(); i != listInt.end(); ++i)
        cout << *i << " ";
    cout << endl;
}在编译时出现如下提示:
c:\program files\microsoft visual studio\vc98\include\functional(16) : error C2143: syntax error : missing '{' before '<'
c:\program files\microsoft visual studio\vc98\include\functional(16) : error C2059: syntax error : '<'
....Why? 
Thx!

解决方案 »

  1.   

    #include <list>
    #include <iostream>
    这两句错误
    应该为:#include <list.h>
    #include <iostream.h>
      

  2.   

    #include <list>
    #include <iostream>
    这两句错误
    应该为:#include <list.h>
    #include <iostream.h>
      

  3.   

    加上.h错误反而更多了
    在我自己上编译运行完全正确,输出结果为:
    1 2 3
    1 2 3 4 4 4
    1 2 3 4 4 4 5 6 7
    1 2 3 4 4 4 5 6 7 10 11 12
    Press any key to continue
      

  4.   

    加.h后错误还不少;
    请问 xnliu(傻子) ,你是如何做的?
      

  5.   

    这个问题解决了。
    皆因上述源文件存为.c的形式,更改为.cpp后编译成功。
    Thanks everyone.