473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to insert a string in vector c++

vector <string> mystring;
mystring.push_back("Hello World");
but when i print after the insertion then i get ("hello") and ("World") as different string.
i need to get ("Hello World ") As one string..
pls help me..
Feb 25 '17 #1
1 5021
weaknessforcats
9,208 Expert Mod 8TB
You are not pushing back a string. "Hello world" is a const char*.

With function overloading, there are many push_back methods and the one used is based on the argument you provide.

Try:

Expand|Select|Wrap|Line Numbers
  1. string obj("Hello World");
  2. mystring.push_back(obj);
The push_back with a const char* argument stops pushing when it gets a whitespace byte. Just like it should if this were C. So you push Hello and it stops.

What is called a string in C is not a string in C++. In C++ a string means a string object. In C++ a C-string is just a \0 terminated array of char.
Feb 25 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
6
by: Dave Reid | last post by:
Hi everyone... I'm pretty much a newbie C++ user, and I've run into a problem. I'm trying to read in a large text file, and then do manipulations on it. I can read it into a large 2-dimensional...
0
by: c_kubie | last post by:
I have an update string getting a list of names that are list1 but not in list2. (Sorry for the lame example) list1 ---- Bill Bill mike tom jim
6
by: Eric Lilja | last post by:
Consider the following code: #include <iostream> #include <string> #include <vector> using namespace std; int main() {
2
by: Curten | last post by:
Hi, I want to read data from a txt-file that looks like this: aaa 4 12.45 bbb 3 7.34 ccc 12 3.45 and store the data in an array of structures. The struct and array are defined...
1
by: =?Utf-8?B?TW9uaWNh?= | last post by:
hi SQL queries does not recognize *$()!.,?/\{};:'"&^+=<>|. if I have a variable alike this: Date = "Thursday, March 01, 2007 - 9:53 PM"; how can I inset in my database? strCommand =...
4
by: Abandoned | last post by:
Hi.. I want to insert some data to postgresql.. My insert code: yer="019" cursor.execute("INSERT INTO ids_%s (id) VALUES (%s)", (yer, id)) I don't want to use % when the insert operation. in...
9
by: shoes2908 | last post by:
Hi, again I am in a rush and can't seem to remember how to search for a certain string in a string vector... heres my code: cin >> worker_num; if (cin.fail()) {...
6
by: Mr. K.V.B.L. | last post by:
I want to start a map with keys but an empty vector<string>. Not sure what the syntax is here. Something like: map<string, vector<string MapVector; MapVector.insert(make_pair("string1",...
1
maheshwag
by: maheshwag | last post by:
If I have to insert with two sql table and the place of string is as below: // Single Record Insert String AA=”Insert into aa(date)values(@date)”; //Multiple Record Insert with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.