经典问题---'cout' /string was not declared in this scope

示例一

#include<stdio.h>
#include<string>

using std::string;
string size="hello!";

int main(){
size.append(1,'w');
cout<<size<<endl;//'cout' was not declared in this scope
return 0;
}

解决

#include<stdio.h>
#include<iostream>//要素一
#include<string>
using namespace std;//要素二

string size="hello!";

int main(){

size.append(1,'w');

cout<<size<<endl;
return 0;
}

示例二

#include<stdio.h>
#include<iostream>
#include<string>


string size="hello!";

int main(){

size.append(1,'w');

cout<<size<<endl;
return 0;
}

解决

#include<stdio.h>
#include<iostream>
#include<string>

using namespace std;//更准确的说法是*--using std::string--*
string size="hello!";

int main(){

size.append(1,'w');

cout<<size<<endl;
return 0;
}

阅读更多

没有更多推荐了,返回首页