Basic "String" data type not functional

Hello, can you please help me understand what is wrong here? Goal is to print value of integer i. In case i is a multiple of 3, then print word "Fizz".
I am getting error:
main.cpp:14:6: error: ‘String’ in namespace ‘std’ does not name a type
std::String printNum() {
^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:31:14: error: ‘printNum’ was not declared in this scope
==========================================================================

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>

using namespace std;

std::String printNum() {

    std::String result;
    for (int i = 1; i < 101; i++) {
        //If number is multiple of 3, print word 'Fizz'
        if (i%3==0) {
            result = "Fizz";
        } else {
            std::string result = to_string(i);
        }
        
    }
    return result;
}

int main()
{
    printNum();
    return 0;
}
The name of the class is exactly std::string, not std::String.

Every user-facing name in the standard library that is not a PREPROCESSOR_MACRO is written in lower_case.
Last edited on
Thank you. Somehow the online compiler I am using was suggesting 'String'. Once I fixed as you suggested the thing worked right away. Appreciated.'


#include <iostream>
#include <string>

using namespace std;

std::string printNum() {

std::string result;
for (int i = 1; i < 101; i++) {
//If number is multiple of 3, print word 'Fizz'
if (i%3==0) {
cout << "Fizz" << endl;

} else {
std::string result = to_string(i);
cout << i << endl;
}

}
return {};
}
Topic archived. No new replies allowed.