Posts Tagged C
C++ Parse Split Delimited String
Posted by admin in C Plus Plus on February 18, 2009
This article teaches you how to parse split delimited string in C++. This is one of the most handful function you can use for delimited string like CSV – comma separated value.
#include <string>
#include <vector>
#include <functional>
#include <iostream>
using namespace std;
void split(const string& s, char c,
vector<string>& v) {
string::size_type i = 0;
string::size_type j = s.find(c);
while (j != string::npos) {
v.push_back(s.substr(i, j-i));
i = ++j;
j = s.find(c, j);
if (j == string::npos)
v.push_back(s.substr(i, s.length( )));
}
}
int main( ) {
vector<string> v;
string s = "Account Name|Address 1|Address 2|City";
split(s, '|', v);
for (int i = 0; i < v.size( ); ++i) {
cout << v[i] << '\n';
}
}
Install C++ Boost on Ubuntu
Posted by admin in C Plus Plus, Linux on February 16, 2009
Boost is probably the most popular C++ library, to install C++ Boost on Ubuntu is easy.
Open your terminal and type the following command to install the packages:
sudo apt-get install libboost-date-time-dev libboost-date-time1.34.1 libboost-dev libboost-doc libboost-filesystem-dev libboost-filesystem1.34.1 libboost-graph-dev libboost-graph1.34.1 libboost-iostreams-dev libboost-iostreams1.34.1 libboost-program-options-dev libboost-program-options1.34.1 libboost-python-dev libboost-python1.34.1 libboost-regex-dev libboost-regex1.34.1 libboost-signals-dev libboost-signals1.34.1 libboost-test-dev libboost-test1.34.1 libboost-thread-dev libboost-thread1.34.1
Hope this helps!
Compile and Run C on Ubuntu
To create a C program and run in on Ubuntu can be easy.
1. Install C and C++ Compilers in Ubuntu
Run the following command in the Ubuntu terminal, it will install all the required packages for C and C++ compilers on Ubuntu
sudo aptitude install build-essential
2. Write a Hello World program in C
sudo gedit hello_world.c
add the following lines save and exit the file
/* Program 1.1 Your Very First C Program - Displaying Hello World */
#include <stdio.h> /* This is a preprocessor directive */
int main(void) /* This identifies the function main() */
{ /* This marks the beginning of main() */
printf("Hello world!"); /* This line displays a quotation */
return 0; /* This returns control to the operating system */
} /* This marks the end of main() */
3. Create an Ubuntu executable using the following command
cc -o hello_world hello_world.c
4. run this executable using the following command
./hello_world
Output should show as follows
Hello, world!
Hope it helps! :)










































