1

Could any one help me to figure out which the following code cannot build successfully:

#include <iostream>

int main(void){

    std::string str1("sfsfasfdsdf");
    std::cout << str1 << std::endl;
    return 1;
}

Thanks.

1
  • 2
    What is error your compiler is giving you? Commented May 22, 2013 at 15:53

1 Answer 1

5

You have to include std::string header:

#include <string>

EDIT: According to @ShafikYaghmour's comments, include iostream sometimes brings in string, but it may not be the case for you if you only have the posted code.

Sign up to request clarification or add additional context in comments.

6 Comments

@ShafikYaghmour Would you please provide source of that? I never realized that this is the case, at least not on Windows.
@ShafikYaghmour: this is implementation-specific. Some do, others don't, the Standard doesn't mandate anything.
@syam I did not say the standard required it, I said depends, I am not sure we have enough information. Although it is a good guess. On ideone it build fine: ideone.com/xoChjb
I think is better and more clear if you specify the headers of the objects in the source file you are using them.
@user1655685 You are welcome. Glad it helped. You may accept my answer by clicking on the \/ sign besides my answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.