[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

int main() { cin >> words; output = "";

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 35
Thread images: 2

File: sonadibit.png (2MB, 800x800px) Image search: [Google]
sonadibit.png
2MB, 800x800px
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] +':');
}
}
>>
>>58724645

 words.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 me
hello 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
Thread posts: 35
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.