int main()
{
cin >> words;
output = "";
int size = words.size();
for (i = 0; i < size; ++i); {
while (i < size); {
output += (":regional_indicator_" + words.at[i] +':');
}
}
cout << words << endl;
return 0;
}
Getting an error C2109 subscript requires array or pointer type...
Not sure I understand this, isn't a string inherently an array of characters?
>>58724645
never mind the cout at the end, I already fixed that to output.
>>58724645
the error is on the line output += ... and pertains to words.at[i] I presume
>>58724645
Wow, that's embarrassing
>>58724645
>isn't a string inherently an array of characters
Yes, but C++ (correctly) tries to hide this from you. Something like words.c_str()[i] might work.
>>58724887
It runs with that but it doesn't print anything
>>58724645
Yes but a function is not an array of characters.
>>58724927
and debugging didn't give me any valuable insight
>>58724927
Probably because you're exiting your for and while loops immediately by putting a semicolon before the loop body
>>58724927
>>58725050
Explain to us exactly what your code is doing here (hint: your error is there):for (i = 0; i < size; ++i); {
while (i < size); {
output += (":regional_indicator_" + words.at[i] +':');
}
}
>>58724645words.at
is a function. You're trying to index a fucking function.words[i]
//or alternatively
words.at(i)
Your fucking loops end with a semicolon;for (i = 0; i < size; ++i)/*----->*/; // <--- see this little nigger?
while (i < size) /*----->*/; // <--- he's fucking your shit up
for and while execute the statement or block that follows it. Statements are delimited with a semicolon. Your code basically does this.for (i = 0; i < size; ++i)
;
{
while(i < size)
;
{
output += (":regional_indicator_" + words.at[i] +':');
}
}
Fucking remove those shitstain semicolons.
Now fuck off with your shitty bait.
Only two anons have stated the blatant problem of this code, fuck neo-/g/.
>>58725136
Thanks. I took out the trouble semi colons. Now when the program is ran and text is entered, it creates a new line and does not close. After a minute it's using 356 MB of my memory...
>>58725136
and sadly this isn't bait. this is the extent of my coding prowess from what I can remember of the programming class I took 4 years ago.
what do you think this does:while (i < size) {
output += (":regional_indicator_" + words.at[i] +':');
}
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string output;
string words;
int i;
int main()
{
cin >> words;
output = "";
int size = words.size();
for (i = 0; i < size; ++i) {
while (i < size) {
output += (":regional_indicator_" + words.c_str()[i] +':');
}
}
cout << output << endl;
return 0;
}
This is where I'm at now. Takes input text then goes into some sort of memory hogging loop and doesn't print the output.
>>58724645
That is some spaghetti code.
>>58725515
From what I'm seeing you need to take a step back and start at square one, anon. Relearn for and while loops and how they're structured.
>>58725508
adds each character in a string to output plus the string of text and char.
>>58725544
Yeah, the second line does the concatenation as you say. But what about the first and last lines, do you really need this block surrounding it? If yes, why?
>>58725515
The while loop will run forever as there is no chance for the i to get an increasement. Remove it
>>58725084
This
This is a sad thread
>>58725515
If as I think you want to display each word of your input with a prefix, you should rather the standard 'std::split' method to get a word array, then use a loop (use a standard iterator if you feel brave enough)
>>58725709
negative, each letter.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string output;
string words;
int i;
int main()
{
cin >> words; // gets words from user
output = ""; // readys the output string
i = 0; // warms up the calculator
int size = words.size(); // size matters
while (i <= size; ++i) { // loops through each character in "words" (can't increment in the function?)
output += ":regional_indicator_" + words.c_str()[i] +':'; // appends output with each letter from words plus a suffix and prefix
}
cout << output << endl; // prints the ouput
return 0;
}
Where did it all go so wrong?
>>58724645
Get rid of the while loop (also the while loop has nothing inside of it because of your ;
If you want to get the character that the i position of words just do words[i].
>>58725949
I took the ; out of the while loop function and added && + i to the code of the loop.
Now the console gives mehello world
[6 blank square characters]
Press any key to continue . . .
>>58724645
>stray semicolon strikes again
OH MY GOD
>>58725205
I count 3 before you and two more calling OP an idiot.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string output;
string words;
int i;
int main()
{
cin >> words; // gets words from user
output = ""; // readys the output string
i = 0; // warms up the calculator
int size = words.size(); // size matters
while (i <= size) { // loops through each character in "words" (can't increment in the function?)
output += ":regional_indicator_" + words[i] +':'; // appends output with each letter from words plus a suffix and prefix
++i;
}
cout << output << endl; // prints the output
return 0;
}
Now when I input "hello world" it outputs "osss" ...
>>58726717
did I accidentally create a new open-source encryption algorithm?
>>58724645
what the fuck are you even trying to accomplish with that nested loop ?
>>58724645
IF this isn't bait, just quit now.
There is no hope for you, if you are this unaware or stupid.
>>58726887
it seems a lot of people here were born knowing C++ syntax. What is your nationality?
pls help im so confused