处理来自多个输入的多行

时间:2017-11-27 10:54:54

标签: c++

首先看看我的代码。

 #include <iostream>

 using namespace std;

 int main()
 {
    int oobjid;         /* Used int to receive the old id of the         
                        object. This will get dumped afterwards */
    string line;       // For receiving rest of the line data.
    int srange;        //starting range
    int nobjid;


    cout << "Enter the start id number:" << endl;
    cin >> srange;

    cout << "Enter the line" << endl;
    cin >> oobjid;
    getline(cin,line);
    cout << "Entered Stating point number: "<< srange
    <<endl;

    while(line.length() != 0){


    nobjid = srange;


   cout << "Updated Line:  "<< nobjid << line << endl;

   srange++;

   }

  return 0;
  }

如何将输入提供给该程序(只是一个基本结构)

14913, PLS_buoy1, PLS_buoy, 299, 0
14915, LOD_PLS_buoy1, LOD_PLS_buoy, 800, 128
14916, PLS_speedlimit25, pls_speedlimit25, 100, 128
14917, PLS_speedlimit55, PLS_speedlimit55, 100, 128
14918, PLS_speedlimit75, PLS_speedlimit75, 100, 128
14919, PLS_constructcrane, PLS_constructcrane, 100, 128
14920, PLS_constructhole, PLS_constructholes, 100, 128
14921, PLS_constructhole1, PLS_constructholes, 100, 128
14922, pls_diner, pls_diner, 100, 128

我的问题:

好吧,正如你已经看到输入的那样,有一个数字(没有它的长度),我在程序中输入为整数,因为它不包含十进制数字。然后对于线的其余部分,我使用了getline(cin,line)将休息作为输入(不确定它包含多少个字符?)。第一个数字将被数字顺序替换,作为起始数字用户输入。然后程序将打印用户输入的值,然后打印该行的其余部分。然后对于第二行,它将输入值,但这次数字将是前一个+ 1.如果第一行数是22334,那么它现在是22334 + 1 = 22335然后第二行的其余部分被粘贴

据我所知,程序从第1行接收输入并继续更新数字,但其余行不会从输入的第2行或第3行更改。

我的意思是程序只从第1行接收输入,第2行和其他行没有输入。我可以使用不同的变量,如line2,line3,line4,但问题是这个行数没有限制。可能有10或100甚至1000行。

那么有什么解决方案吗?提前谢谢。

为我糟糕的英语而烦恼很长的帖子,因为我想让每个人都清楚程序应该做什么。

编辑:现在我已经设法解决了这个问题,但是在我再次按回车键之前,最后输入的行没有处理。

0 个答案:

没有答案
相关问题