#c++ string question

1 messages · Page 1 of 1 (latest)

hexed fjord
#

how do I write a code for this? how do I make a array of a string?
#include <iostream>
using namespace std;

int main()
{
int k;
cin >> k;
string emtystring = "";
for (int i = 1; i < k + 1; i ++)
{
string name;
cin >> name;
emtystring += name;
}
cout << emtystring << endl;
}
this is the code I wrote

quiet pawnBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

bleak sky
#

you dont have the <string> header

hexed fjord
#

so if I add #include <string.h> does it work?

bleak sky
#

string

#

just that

hexed fjord
#

ok

bleak sky
#

but there might be a few more errors

#

not entirely sure

hexed fjord
#

in the problem it gives me a hint to make an empty string and add the strings in the front. how do I add strings to the front of another string?

bleak sky
#

thats easy

hexed fjord
#

oh do I do that replace string?

bleak sky
#

string STRING = thestringyouwant + "";

#

no that wont work

hexed fjord
bleak sky
#

STRING.append("");

hexed fjord
#

can I use this one to add to the front?

#

like I didin't learn that much and the problems require to use the codes that they teached.

bleak sky
#

heres the thing.

#

i dont have much time

#

i have things to do

hexed fjord
#

ok

bleak sky
#

ask chatgpt

hexed fjord
#

ok thx

bleak sky
#

its better than you think

finite flume
finite flume
hexed fjord
#

ok

bleak sky
#

. chatGPT is merely a tool, not a teacher, yes. but when you have no idea how to do something, you can ask it and find out

finite flume
#

find out what, exactly?

#

it's a language model that's very good at being convincing

torn terrace
#

you will need

  #include <string>```for the second option
hexed fjord
#

ok thx