Text 从文本文件到变量逐行读取

Text 从文本文件到变量逐行读取,text,getline,Text,Getline,我想逐行读取文本文件内容并分配给变量。我该怎么做?我将用C书写,不应该有'\n'字符 文本文件内容: 9600 502 N 1 8 N 变数 int baudrate; int port; char parity; char databits; char stopbit; while (fgets(line, sizeof(line), file)) { printf(line); } 为此指定一种语言。 Specify the path of

我想逐行读取文本文件内容并分配给变量。我该怎么做?我将用C书写,不应该有'\n'字符

文本文件内容:

9600
502
N
1
8
N
变数

int     baudrate;
int     port;
char    parity;
char    databits;
char    stopbit;


while (fgets(line, sizeof(line), file)) {
    printf(line);
}

为此指定一种语言。
Specify the path of the file from where you would get the file in the path variable.

string path = '' // File path which needs to be read. 
string[] readText = File.ReadAllLines(path);

If the number of lines in the files is fixed and the variables in which you want the values to be saved remains the same it can be done as under : 

baudrate = Convert.ToInt32(readText[0]);
port = Convert.ToInt32(readText[1]);
parity = Convert.ToChar(readText[2]);
databits = Convert.ToChar(readText[3]);
stopbit= Convert.ToChar(readText[4]);