ILOG CPLEX 11.0 Getting Started > Tutorials > Concert Technology Tutorial for C++ Users > Writing and Reading Models and Files

In example ilolpex1.cpp, one line is still unexplained:

cplex.exportModel("lpex1.lp");

This statement causes cplex to write the model it has currently extracted to the file called lpex1.lp. In this case, the file will be written in LP format. (Use of that format is documented in the reference manual ILOG CPLEX File Formats.) Other formats supported for writing problems to a file are MPS and SAV (also documented in the reference manual ILOG CPLEX File Formats). IloCplex decides which file format to write based on the extension of the file name.

IloCplex also supports reading of files through one of its importModel methods. A call to cplex.importModel(model, "file.lp") causes ILOG CPLEX to read a problem from the file file.lp and add all the data in it to model as new objects. (Again, MPS and SAV format files are also supported.) In particular, ILOG CPLEX creates an instance of

for the objective function found in file.lp
for each variable found in file.lp, except 
for each semi-continuous or semi-integer variable found in file.lp, 
for each row found in file.lp
for each SOS of type 1 found in file.lp, and 
for each SOS of type 2 found in file.lp

If you also need access to the modeling objects created by importModel, two additional signatures are provided:

void IloCplex::importModel(IloModel& m,
                           const char* filename,
                           IloObjective& obj,
                           IloNumVarArray vars,
                           IloRangeArray  rngs) const;

and

void IloCplex::importModel(IloModel& m,
                           const char* filename,
                           IloObjective& obj,
                           IloNumVarArray vars,
                           IloRangeArray rngs,
                           IloSOS1Array sos1,
                           IloSOS2Array sos2) const;

They provide additional arguments so that the newly created modeling objects will be returned to the caller. Example program ilolpex2.cpp gives an example of how to use method importModel.