Need to use StringStream to take user input, and pass it (as a string) into my function

Hello,

I need to write a program that uses a stack to match parenthesis, brackets and curly braces. I think I got that mostly right, if I didn't miss anything. I also need my main function to repeatedly input lines, and to quit when a blank line is read. For each line, I just need that to be passed as an argument into my "balanced" function, as a string.

I'm sure it's pretty simple, but I'm just not getting it right now...Also, I deliberately left out the pop, top, push, etc. functions for the sake of simplicity. If you need them, I will happily post...but my issue is strictly with the main function, and with stringstream.

Thanks.

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

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

void print (const string & expr);

int main(){
    
    
    cout << "\nPlease enter your expression - enter a blank line to quit. \n";
    
    do {
        
        string line;
        getline(cin, line);
        
        stringstream ss(line);
        
        print(line);
        
    }

while (line.size() != 0 )
    
    return 0;
    
}

void print (const string & expr){
    
 for (int i = 0; i < expr.size(); i++){

        cout << expr[i];   

}
Last edited on
EDIT: Since my question is mainly concerning stringstream, I changed my function to just a basic function that prints the string that was passed to it. I don't want to distract from my main issue.
Last edited on
Topic archived. No new replies allowed.