Question: When reading from a file, we have two ways to 

Way 1:

```
ifstream fin("data.txt"); 
const int LINE_LENGTH = 100; 
char str[LINE_LENGTH];  
while( fin.getline(str,LINE_LENGTH) )
{    
    cout << "Read from file: " << str << endl;
}

```

Way 2:

```
ifstream fin("data.txt");  
string s;  
while( getline(fin,s) )
{    
    cout << "Read from file: " << s << endl; 
}

```

which is better? Personlly, I prefer way2 since I don't need to specify max length, what's your comments?

Answer: 
Prior to Sass **3.4**, this is just not possible at all. The deal-breaking features here are the ability to store the current selector into a variable and the ability to split a string (though the later could be created via SassScript functions).

```
@mixin append-attr($x) {
    $sel: &;
    $collector: ();

    @for $i from 1 through length($sel) {
        $s: nth($sel, $i);
        $last: nth($s, -1);
        @if str-slice($last, -1) == "]" {
            // if is just the bare attribute with no value, $offset will be -1, otherwise it will be -2
            $offset: -1;
            $current-x: $x;

            @if str-slice($last, -2) == '"]' {
                // this attribute already has a value, so we need to adjust the offset
                $offset: -2;
            } @else {
                // no attribute value, so add the equals and quotes
                $current-x: '="' + $x + '"';
            }
            $last: str-slice($last, 1, $offset - 1) + $current-x + str-slice($last, $offset);
            $collector: append($collector, set-nth($s, -1, $last), comma);
        } @else {
            // following line will append $x to your non-attribute selector
            $collector: append($collector, selector-append($s, $x), comma);
            // the following line will not change your non-attribute selector at all
            //$collector: append($collector, $s, comma);
        }
    }

    @at-root #{$collector} {
        @content;
    }
}

```

Usage:

```
[data-product] {
    color: white;

    @include append-attr("red") {
        color: red;

        @include append-attr('-green') {
            color: green;
        }
    }
}

[one], [two] {
    color: orange;

    @include append-attr('alpha') {
        color: yellow;
    }
}

[test], .test {
    @include append-attr('-one') {
        color: red;
    }
}

.bar input[min] {
    @include append-attr('5') {
        background: yellow;
    }
}

```

Output:

```
[data-product] {
  color: white;
}
[data-product="red"] {
  color: red;
}
[data-product="red-green"] {
  color: green;
}

[one], [two] {
  color: orange;
}
[one="alpha"], [two="alpha"] {
  color: yellow;
}

[test="-one"], .test-one {
  color: red;
}

.bar input[min="5"] {
  background: yellow;
}

```

Related: [Modifying the middle of a selector in Sass (adding/removing classes, etc.)](https://stackoverflow.com/questions/28593476/modifying-the-middle-of-a-selector-in-sass-adding-removing-classes-etc)
```css
input[data-product] {
 color: #000;
}
input[data-product=red] {
 color: #f00;
}
```

You do not need to nest, the second style will override the first.