Weird 'string' declared here error. Trying to program pyramid of asterisks












1















I'm new to C++, so I'm still trying to figure out how to do basic debugging from errors printed on the terminal. I'm trying to print a pyramid of asterisks (*), but I keep getting this error that says "'string' declared here". /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:194:65: note:
'string' declared here
typedef basic_string, allocator > string;
^
1 error generated.



I've tried looking up how to read some of these errors in C++, but haven't been able to find a useful guide that isn't written in some alien technical gibberish. So if you could dumb down the explanation a little that would be great.



#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

String printAst(int number){
for(int i = 0; i < number; i++){
cout << "* ";
}
}
int main(){

printAst(3);
//***
//**
//*
return 0;

}


I have the expected print out listed in //










share|improve this question























  • One obvious potential problem is that the printAst() function returns a string, but you have no return statement.

    – Tim Biegeleisen
    Jan 1 at 7:40











  • That isn't an error message it's a note about the error message on the line above in the compiler output

    – Alan Birtles
    Jan 1 at 7:41






  • 1





    The error message probably says something like "String is undefined, did you mean string?"

    – Alan Birtles
    Jan 1 at 7:43











  • You need to print 'n' to go to the next line.

    – stark
    Jan 1 at 14:37











  • @TimBiegeleisen I was confused about the return type, since I couldn't figure out whether cout counted as a string return, or whether I should have made the return type void

    – pancham2016
    Jan 2 at 23:57
















1















I'm new to C++, so I'm still trying to figure out how to do basic debugging from errors printed on the terminal. I'm trying to print a pyramid of asterisks (*), but I keep getting this error that says "'string' declared here". /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:194:65: note:
'string' declared here
typedef basic_string, allocator > string;
^
1 error generated.



I've tried looking up how to read some of these errors in C++, but haven't been able to find a useful guide that isn't written in some alien technical gibberish. So if you could dumb down the explanation a little that would be great.



#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

String printAst(int number){
for(int i = 0; i < number; i++){
cout << "* ";
}
}
int main(){

printAst(3);
//***
//**
//*
return 0;

}


I have the expected print out listed in //










share|improve this question























  • One obvious potential problem is that the printAst() function returns a string, but you have no return statement.

    – Tim Biegeleisen
    Jan 1 at 7:40











  • That isn't an error message it's a note about the error message on the line above in the compiler output

    – Alan Birtles
    Jan 1 at 7:41






  • 1





    The error message probably says something like "String is undefined, did you mean string?"

    – Alan Birtles
    Jan 1 at 7:43











  • You need to print 'n' to go to the next line.

    – stark
    Jan 1 at 14:37











  • @TimBiegeleisen I was confused about the return type, since I couldn't figure out whether cout counted as a string return, or whether I should have made the return type void

    – pancham2016
    Jan 2 at 23:57














1












1








1








I'm new to C++, so I'm still trying to figure out how to do basic debugging from errors printed on the terminal. I'm trying to print a pyramid of asterisks (*), but I keep getting this error that says "'string' declared here". /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:194:65: note:
'string' declared here
typedef basic_string, allocator > string;
^
1 error generated.



I've tried looking up how to read some of these errors in C++, but haven't been able to find a useful guide that isn't written in some alien technical gibberish. So if you could dumb down the explanation a little that would be great.



#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

String printAst(int number){
for(int i = 0; i < number; i++){
cout << "* ";
}
}
int main(){

printAst(3);
//***
//**
//*
return 0;

}


I have the expected print out listed in //










share|improve this question














I'm new to C++, so I'm still trying to figure out how to do basic debugging from errors printed on the terminal. I'm trying to print a pyramid of asterisks (*), but I keep getting this error that says "'string' declared here". /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:194:65: note:
'string' declared here
typedef basic_string, allocator > string;
^
1 error generated.



I've tried looking up how to read some of these errors in C++, but haven't been able to find a useful guide that isn't written in some alien technical gibberish. So if you could dumb down the explanation a little that would be great.



#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

String printAst(int number){
for(int i = 0; i < number; i++){
cout << "* ";
}
}
int main(){

printAst(3);
//***
//**
//*
return 0;

}


I have the expected print out listed in //







c++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 7:37









pancham2016pancham2016

11




11













  • One obvious potential problem is that the printAst() function returns a string, but you have no return statement.

    – Tim Biegeleisen
    Jan 1 at 7:40











  • That isn't an error message it's a note about the error message on the line above in the compiler output

    – Alan Birtles
    Jan 1 at 7:41






  • 1





    The error message probably says something like "String is undefined, did you mean string?"

    – Alan Birtles
    Jan 1 at 7:43











  • You need to print 'n' to go to the next line.

    – stark
    Jan 1 at 14:37











  • @TimBiegeleisen I was confused about the return type, since I couldn't figure out whether cout counted as a string return, or whether I should have made the return type void

    – pancham2016
    Jan 2 at 23:57



















  • One obvious potential problem is that the printAst() function returns a string, but you have no return statement.

    – Tim Biegeleisen
    Jan 1 at 7:40











  • That isn't an error message it's a note about the error message on the line above in the compiler output

    – Alan Birtles
    Jan 1 at 7:41






  • 1





    The error message probably says something like "String is undefined, did you mean string?"

    – Alan Birtles
    Jan 1 at 7:43











  • You need to print 'n' to go to the next line.

    – stark
    Jan 1 at 14:37











  • @TimBiegeleisen I was confused about the return type, since I couldn't figure out whether cout counted as a string return, or whether I should have made the return type void

    – pancham2016
    Jan 2 at 23:57

















One obvious potential problem is that the printAst() function returns a string, but you have no return statement.

– Tim Biegeleisen
Jan 1 at 7:40





One obvious potential problem is that the printAst() function returns a string, but you have no return statement.

– Tim Biegeleisen
Jan 1 at 7:40













That isn't an error message it's a note about the error message on the line above in the compiler output

– Alan Birtles
Jan 1 at 7:41





That isn't an error message it's a note about the error message on the line above in the compiler output

– Alan Birtles
Jan 1 at 7:41




1




1





The error message probably says something like "String is undefined, did you mean string?"

– Alan Birtles
Jan 1 at 7:43





The error message probably says something like "String is undefined, did you mean string?"

– Alan Birtles
Jan 1 at 7:43













You need to print 'n' to go to the next line.

– stark
Jan 1 at 14:37





You need to print 'n' to go to the next line.

– stark
Jan 1 at 14:37













@TimBiegeleisen I was confused about the return type, since I couldn't figure out whether cout counted as a string return, or whether I should have made the return type void

– pancham2016
Jan 2 at 23:57





@TimBiegeleisen I was confused about the return type, since I couldn't figure out whether cout counted as a string return, or whether I should have made the return type void

– pancham2016
Jan 2 at 23:57












1 Answer
1






active

oldest

votes


















0














Here is a corrected version of your code. The immediate cause of your current errors appears to have been the String return type of the printAst() function. If you wanted to return a string, then you probably intended to use std::string, not String. But, even after fixing this, I noticed that your logic for printing the pyramid also had a problem, so I fixed that too.



void printAst (int number) {
for (int i=0; i < number; ++i) {
for (int j=0; j < number-i; ++j) {
cout << "* ";
}
cout << "n";
}
}

int main() {
printAst(3);
return 0;
}

* * *
* *
*


The major changes I made include using a double for loop to print the inverse pyramid. The logic is that there are number levels to the pyramid, and at each level we print number count of asterisks.



Also, since printAst does not return anything, I changed the return type to void.






share|improve this answer
























  • Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

    – pancham2016
    Jan 3 at 0:04











  • The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

    – Tim Biegeleisen
    Jan 3 at 0:12











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993814%2fweird-string-declared-here-error-trying-to-program-pyramid-of-asterisks%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Here is a corrected version of your code. The immediate cause of your current errors appears to have been the String return type of the printAst() function. If you wanted to return a string, then you probably intended to use std::string, not String. But, even after fixing this, I noticed that your logic for printing the pyramid also had a problem, so I fixed that too.



void printAst (int number) {
for (int i=0; i < number; ++i) {
for (int j=0; j < number-i; ++j) {
cout << "* ";
}
cout << "n";
}
}

int main() {
printAst(3);
return 0;
}

* * *
* *
*


The major changes I made include using a double for loop to print the inverse pyramid. The logic is that there are number levels to the pyramid, and at each level we print number count of asterisks.



Also, since printAst does not return anything, I changed the return type to void.






share|improve this answer
























  • Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

    – pancham2016
    Jan 3 at 0:04











  • The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

    – Tim Biegeleisen
    Jan 3 at 0:12
















0














Here is a corrected version of your code. The immediate cause of your current errors appears to have been the String return type of the printAst() function. If you wanted to return a string, then you probably intended to use std::string, not String. But, even after fixing this, I noticed that your logic for printing the pyramid also had a problem, so I fixed that too.



void printAst (int number) {
for (int i=0; i < number; ++i) {
for (int j=0; j < number-i; ++j) {
cout << "* ";
}
cout << "n";
}
}

int main() {
printAst(3);
return 0;
}

* * *
* *
*


The major changes I made include using a double for loop to print the inverse pyramid. The logic is that there are number levels to the pyramid, and at each level we print number count of asterisks.



Also, since printAst does not return anything, I changed the return type to void.






share|improve this answer
























  • Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

    – pancham2016
    Jan 3 at 0:04











  • The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

    – Tim Biegeleisen
    Jan 3 at 0:12














0












0








0







Here is a corrected version of your code. The immediate cause of your current errors appears to have been the String return type of the printAst() function. If you wanted to return a string, then you probably intended to use std::string, not String. But, even after fixing this, I noticed that your logic for printing the pyramid also had a problem, so I fixed that too.



void printAst (int number) {
for (int i=0; i < number; ++i) {
for (int j=0; j < number-i; ++j) {
cout << "* ";
}
cout << "n";
}
}

int main() {
printAst(3);
return 0;
}

* * *
* *
*


The major changes I made include using a double for loop to print the inverse pyramid. The logic is that there are number levels to the pyramid, and at each level we print number count of asterisks.



Also, since printAst does not return anything, I changed the return type to void.






share|improve this answer













Here is a corrected version of your code. The immediate cause of your current errors appears to have been the String return type of the printAst() function. If you wanted to return a string, then you probably intended to use std::string, not String. But, even after fixing this, I noticed that your logic for printing the pyramid also had a problem, so I fixed that too.



void printAst (int number) {
for (int i=0; i < number; ++i) {
for (int j=0; j < number-i; ++j) {
cout << "* ";
}
cout << "n";
}
}

int main() {
printAst(3);
return 0;
}

* * *
* *
*


The major changes I made include using a double for loop to print the inverse pyramid. The logic is that there are number levels to the pyramid, and at each level we print number count of asterisks.



Also, since printAst does not return anything, I changed the return type to void.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 7:43









Tim BiegeleisenTim Biegeleisen

227k1394147




227k1394147













  • Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

    – pancham2016
    Jan 3 at 0:04











  • The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

    – Tim Biegeleisen
    Jan 3 at 0:12



















  • Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

    – pancham2016
    Jan 3 at 0:04











  • The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

    – Tim Biegeleisen
    Jan 3 at 0:12

















Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

– pancham2016
Jan 3 at 0:04





Ya, I ended up reaching the same conclusion regarding the typing being void and using the nested for loop. What I'm still confused about is how I know the type should be void. I thought initially since I'm printing a string "*" the return type should be string, but now I'm not sure.

– pancham2016
Jan 3 at 0:04













The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

– Tim Biegeleisen
Jan 3 at 0:12





The printAst function does not actually return any value, thus it should be void. That is prints out a string has nothing to do with its return behavior.

– Tim Biegeleisen
Jan 3 at 0:12




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993814%2fweird-string-declared-here-error-trying-to-program-pyramid-of-asterisks%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas