string print problem

i used

cin >> A >> B >> C;
getline(cin , D);

and try to print out

cout << A << B << C << D; something like this

but there is always space between beginning of print and A

like

[unwanted space is here] 5000 jake min 3000

i want to print like

5000 jake min 3000

i used /b/b in front of A bout <<"\b"<< A << B << C....

but not working

any idea?


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std; 
struct res{
    double A;
    string U;
    double R;
    string P;
    
};

int main (int argc, const char * argv[])
{
    double A=0.0;
    string U;
    double R=0.0;
    string P;
    vector<res> vec;
    double percentage=0.0;
    while( true ){
        
        cin >> A >> U >> R ; 
        getline(cin,P);
        
        if( A < 0 ) {
            cout << "Provides no significant amount of:"<<endl;
            for(size_t i=0 ; i < vec.size(); i++){
                cout << vec[i].P <<endl;
            }
            break;
            
        }
        //cout << "here" <<endl;
        
        
        percentage = (A/R) * 100.0;
        
        
        
        if(percentage >= 1){
        cout <<"\b\b\b";
        cout << P;
        cout <<" "<<setprecision(1) <<fixed <<A <<" ";
        cout << U <<" " <<setprecision(0)<<fixed<<percentage<<"%"<<endl; 
        
        }else if( percentage < 1){
            res pair;
            pair.A = A;
            pair.U = U;
            pair.R = R;
            pair.P = P;
            
            vec.push_back(pair);
            
        }
        
    }
    
}



Sample Input

3500.0 iu 5000.0 Vitamin A
60.0 mg 60.0 Vitamin C
0.15 g 25.0 Fiber
109. mg 990. Phosphorus
0.0 mg 1000.0 Calcium
25.0 mg 20.0 Niacin
-1.0 x 0.0 x
Sample Output

Vitamin A 3500.0 iu 70%
Vitamin C 60.0 mg 100%
Phosphorus 109.0 mg 11%
Niacin 25.0 mg 125%
Provides no significant amount of:
Fiber
Calcium
Last edited on
use cin.ignor() for removing that space.

        cin >> A >> U >> R ;
        cin.ignore();
        getline(cin,P);


That's working on my PC let me know if any problem arise.
Last edited on
Topic archived. No new replies allowed.