help me plz

if i wanna say "do it even the line is over",how can i say it with limitation
maybe like this (??????!="\n"

i wanna give some numbers from notepad like
12.2 21 32 32
332 234 543 5642
234 433
i wanna say give just the first line.or in other words do something to the end of first or second line,got it?
Last edited on
Could you give more details please. What do you mean by "line", is it a string? What do you mean by "over"?

i wanna give some numbers from notepad like
12.2 21 32 32
332 234 543 5642
234 433
i wanna say give just the first line.or in other words do something to the end of first or second line,got it?
Well, you could use getline() to read the whole line and then process the contents of the line. Possibly a stringstream might be useful for parsing its contents.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int main ()
{
    ifstream fin("input.txt");
    string line;
    double num;
    double total;
    
    while (getline(fin, line))
    {
        total = 0;
        istringstream ss(line);
        while (ss >> num)
        {
            total += num;
            cout << setw(8) << num << " ";
        }
        cout << "  Total: " << total << endl;    
    }
}

Output:
    12.2       21       32       32   Total: 97.2
     332      234      543     5642   Total: 6751
     234      433   Total: 667
Last edited on
ok ,i use getline,now what must i do?
plz write it for me
maybe u min change string to number?yeah? with witch function?
yes he meant convert it to a number from word using the string streams and parsing and the function used is operator >>
operator?????give me an example plz
give me an example plz

Just scroll up the page ... http://www.cplusplus.com/forum/beginner/117410/#msg640539

And here's the reference page for the >> operator:
http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/
Last edited on
i write a program to show me row and column of file like above but that not answering in correct me.plz tell me my mistake.
#include <iostream>
#include <string>
#include<fstream>
using namespace std;

int main()
{
string s,ss;
double x,y,z;
int * f;
int a,b,c,i,j,row,col;
ifstream A;
ofstream B;
ifstream C;
A.open("C:/Users/milad/Desktop/miladam.txt");

i=0;

while (!A.eof())
{
getline(A,s);
A>>s;
i++;
}
row=i;
A.close();

f=new int [row];

for(j=0;j<row;j++)
{
getline(A,ss);

B.open("C:/Users/milad/Desktop/miladam1.txt");
B<<ss;
B.close();
C.open("C:/Users/milad/Desktop/miladam1.txt");
col=0;
while(!C.eof())
{
C>>z;
col++;
}
C.close();
cout<<col;
}
cin>>x;
return 0;
}

Topic archived. No new replies allowed.