using std namespace for a line

Im wondering if there is a way to use std namespace for just a specific line instead of typing std:: each time it is required in the same line ?

this is just some incomplete code im trying to write but im wonering for that line is there a way to make it use std for the entire line and not having to type it out each time ?
1
2
3
4
void list(PRODUCT p[], int size)
{
std::cout << std::fixed << std::left;
}
"using" statements only apply to the scope they are declared in, so you have a few approximations available.

(1) Limit it to the body of the function
1
2
3
4
5
6
7
void list(PRODUCT p[], int size)
{
    using namespace std;
    cout << fixed << left;

    cout << "(But this also is within the same scope)\n";
}


(2) Put the necessary statement(s) in their own scope within { and }.
1
2
3
4
5
6
7
8
9
void list(PRODUCT p[], int size)
{
    {
        using namespace std;
        cout << fixed << left;
    }

    std::cout << "Now this line needs 'std'";
}


There's no way I know of to target an individual line; it's about all scope.
Last edited on
Topic archived. No new replies allowed.